Created
April 23, 2011 09:04
-
-
Save johnclaus/938485 to your computer and use it in GitHub Desktop.
Project Euler solutions http://projecteuler.net/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_number(num): | |
return (num % 3 == 0 or num % 5 == 0) | |
def sum_it(upto): | |
sum = 0 | |
for i in range(1, upto): | |
if check_number(i): sum += i | |
return sum | |
print sum_it(1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts (0...1000).select { |n| n % 3 == 0 || n % 5 == 0 }.inject(0) { |s,n| s += n } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(euler001). | |
-export([sumnaturals/0]). | |
sumnaturals() -> | |
lists:sum([A || A <- lists:seq(1,999), (A rem 3 =:= 0) or (A rem 5 =:= 0)]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment