Skip to content

Instantly share code, notes, and snippets.

@albertein
Created February 10, 2012 18:53
Show Gist options
  • Save albertein/1791626 to your computer and use it in GitHub Desktop.
Save albertein/1791626 to your computer and use it in GitHub Desktop.
First challenge for http://apply.embed.ly
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