Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created May 27, 2011 07:47
Show Gist options
  • Save johana-star/994815 to your computer and use it in GitHub Desktop.
Save johana-star/994815 to your computer and use it in GitHub Desktop.
Euler Project Problem #020
# Solution to Project Euler's twentieth problem
# http://projecteuler.net/index.php?section=problems&id=20
# Find the sum of all the digits in 100 factorial.
def factorial(number)
product = 1
(1..number).each {|n| product = product * n}
return product
end
def generate_array(number)
number = number.to_s
array = []
(0..number.length-1).each {|n| array.push number.slice(n).to_i}
return array
end
def sum_array(array)
sum = 0
array.each {|n| sum = sum + n}
return sum
end
number = 100
number = factorial(number)
p number
digits = generate_array(number)
p digits
sum = sum_array(digits)
p sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment