Friday, April 15, 2011

Project Euler problem N° 1 in Ruby

http://projecteuler.net/index.php?section=problems&id=1



def addMultiplesOf(n,range)
nb_of_multiples = 1 + range/n
res = n*((nb_of_multiples/2)*(nb_of_multiples-1))
return res
end

N = 999

puts addMultiplesOf(3,N) + addMultiplesOf(5,N) - addMultiplesOf(15,N)


Project Euler is avery interesting site proposing dozens of very amusing and challenging mathematical and computational problems. Give it try, it is well worth your time.