Sunday, September 19, 2010

Project Euler 001

I have decided to use this blog to display the source code for Project Euler answers (and eventually other programming challenges as well).  Enjoy!
#Project Euler
#Problem 1

x , total = 0,0
while x < 1000
  total += x if x % 3 == 0 || x % 5 == 0
  x+=1
end
range = 0..999
a = range.inject(0) do |sum,element|
  element%3==0 || element%5==0 ? sum+element : sum
end
puts total
puts a

9 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. nice post! Come check out my SC2 blog for good zerg strategy tips =)

    http://zergitup.blogspot.com/

    ReplyDelete
  3. @TSFan: Yeah, it's a fun fusion of Mathematical challenges and Ruby coding. Check it out at www.projecteuler.com

    ReplyDelete