Created
February 10, 2012 18:53
-
-
Save albertein/1791626 to your computer and use it in GitHub Desktop.
First challenge for http://apply.embed.ly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(number) | |
total = 1 | |
for i in 1..number | |
total = total * i | |
end | |
return total | |
end | |
def sum_digits(number) | |
string = number.to_s | |
sum = 0 | |
string.chars { |c| sum += c.to_i } | |
return sum | |
end | |
def solve_sum_factorial(sum) | |
for i in 1..1000 | |
if sum_digits(factorial(i)) == sum | |
puts i | |
break | |
end | |
end | |
end | |
solve_sum_factorial(8001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment