Last active
December 11, 2015 14:38
-
-
Save alexhemard/4615427 to your computer and use it in GitHub Desktop.
mountain lion problems
This file contains hidden or 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
~ $ /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 |
This file contains hidden or 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
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this is an issue w/ BigNum in Mountain Lion
http://stackoverflow.com/questions/12009799/exponentiation-in-ruby-1-8-7-returns-wrong-answers
http://openradar.appspot.com/11806241