Skip to content

Instantly share code, notes, and snippets.

@dinedal
Created February 10, 2012 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinedal/1792525 to your computer and use it in GitHub Desktop.
Save dinedal/1792525 to your computer and use it in GitHub Desktop.
class Integer
def factorial_iterative
f = 1; for i in 1..self; f *= i; end; f
end
def sum_digits
self.to_s.split(//).collect { |d| d.to_i}.sum
end
end
### Bruteforce!
(1..1000).each do |cur|
puts cur and break if cur.factorial.sum_digits == 8001
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment