Skip to content

Instantly share code, notes, and snippets.

@johnclaus
Created April 23, 2011 09:04
Show Gist options
  • Save johnclaus/938485 to your computer and use it in GitHub Desktop.
Save johnclaus/938485 to your computer and use it in GitHub Desktop.
Project Euler solutions http://projecteuler.net/
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)
puts (0...1000).select { |n| n % 3 == 0 || n % 5 == 0 }.inject(0) { |s,n| s += n }
-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