JOEZACK.COM Code Musings and Such

25May/094

Project Euler: Problem 20 in Ruby

I cheesed out on this one, pretty much just did what the problem called for. No magic. Looking through the forums, however, it was pretty much par for the course.

Problem #20

Find the sum of the digits in the number 100!

product, sum = 1, 0

100.times do |i|
  product *= i + 1
end

while product > 0
  sum += (product /= 10) % 10
end

puts sum
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Comments (4) Trackbacks (0)
  1. my wireless router at home overheated when i used p2p heavily for 24 hours for the next 25 days “

  2. wireless routers are very necessary nowadays because we do not want so many wires running around the home ;::

  3. ‘-: I am very thankful to this topic because it really gives useful information “.-

  4. ‘:, I am really thankful to this topic because it really gives great information ~-”


Leave a comment

(required)

No trackbacks yet.