Skip to content

Instantly share code, notes, and snippets.

@rohit89
Created February 11, 2012 12:20
Show Gist options
  • Save rohit89/1799173 to your computer and use it in GitHub Desktop.
Save rohit89/1799173 to your computer and use it in GitHub Desktop.
Embedly Challenge #1
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