Skip to content

Instantly share code, notes, and snippets.

@alexhemard
Last active December 11, 2015 14:38
Show Gist options
  • Save alexhemard/4615427 to your computer and use it in GitHub Desktop.
Save alexhemard/4615427 to your computer and use it in GitHub Desktop.
mountain lion problems
~ $ /usr/bin/ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
~ $ /usr/bin/ruby swag.rb
794
~ $ ruby -v
ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-darwin12.2.0]
~ $ ruby swag.rb
787
#! /usr/bin/ruby
def find_sum_factorial
k = 1
while true
k += 1
sum = sum_digits(factorial(k))
if sum == 8001
puts k
break
end
end
end
def factorial(n)
n.downto(1).inject(:*)
end
def sum_digits(n)
n.to_s.split(//).reduce(0) {|sum, i| sum + i.to_i}
end
find_sum_factorial
@alexhemard
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment