Created
February 11, 2012 12:20
-
-
Save rohit89/1799173 to your computer and use it in GitHub Desktop.
Embedly Challenge #1
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 fact n | |
return 1 if n == 0 | |
n.downto(1).inject(1) {|res, i| res *= i; res} | |
end | |
def sum n | |
n.to_s.each_char.map{|ch| ch.to_i}.inject(0) {|sum, i| sum += i; sum} | |
end | |
(400..1000).each do |i| # fact 400 has 869 digits...close to the 889 required | |
if sum(fact i) == 8001 | |
puts i | |
break | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment