Created
February 20, 2018 12:31
-
-
Save epidemian/eb7aca6469ac068fde49fd5c8cbc54e2 to your computer and use it in GitHub Desktop.
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
# "Proof" of https://twitter.com/tweetsauce/status/965259567322943490 | |
# 1 = 1! | |
# 2 = 2! | |
# 145 = 1! + 4! + 5! | |
# 40,585 = 4! + 0! + 5! + 8! + 5! | |
# These are the only four numbers with this property. | |
# Store the factorials from 0 to 9 for later use. | |
factorials = (0..9).map {|n| (1..n).inject(:*) || 1 } | |
# First show that from N=7 onwards the number 999...9 consisting of N 9's is | |
# bigger than the sum of its digits' factorials. | |
(1..10).each do |n| | |
test = ('9' * n).to_i > n * factorials[9] | |
puts "#{('9' * n).to_i} #{test ? '>' : '<='} #{(['9!'] * n).join(' + ')}" | |
break if test | |
end | |
# And now brute force our way up to 7 9's: | |
(1..9_999_999).each do |n| | |
if n == n.digits.map{ |d| factorials[d] }.sum | |
puts "#{n} = #{n.digits.reverse.map {|d| "#{d}!"}.join(' + ')}" | |
end | |
end | |
# Output: | |
# 9 <= 9! | |
# 99 <= 9! + 9! | |
# 999 <= 9! + 9! + 9! | |
# 9999 <= 9! + 9! + 9! + 9! | |
# 99999 <= 9! + 9! + 9! + 9! + 9! | |
# 999999 <= 9! + 9! + 9! + 9! + 9! + 9! | |
# 9999999 > 9! + 9! + 9! + 9! + 9! + 9! + 9! | |
# 1 = 1! | |
# 2 = 2! | |
# 145 = 1! + 4! + 5! | |
# 40585 = 4! + 0! + 5! + 8! + 5! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment