Last active
November 16, 2020 05:30
-
-
Save inertia186/9d00888ac1315cf955915e1869341c04 to your computer and use it in GitHub Desktop.
My attempt at figuring out what's special about 277777788888899? (see: https://hive.blog/math/@inertia/my-attempt-at-figuring-out-what-s-special-about-277777788888899)
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
def per(n, s) | |
# Summary of the current test by showing the numbere bing tested followed by | |
# the number of digits. | |
puts("#{n} (digits: #{n.to_s.size})") | |
# Increment the step. | |
s = s + 1 | |
# Check if we've reached the last step. | |
if n.to_s.size < 2 | |
puts('Done. Steps: %d' % s) | |
exit(s) | |
end | |
# Make a new result by multiplying each digit. | |
r = 1 | |
n.to_s.split('').each do |m| | |
r = r * m.to_i | |
end | |
# Recursively try the new result. | |
per(r, s) | |
end | |
# If you have a number you want to try, pass it as the argument. Otherwise, | |
# we'll pick a random number. | |
n = if ARGV.length == 0 | |
puts 'Trying random number.' | |
# But not *too* random. We avoid random numbers that have zeros and fives. | |
while rnd = rand(10**15) | |
break unless (rnd.to_s.split('') & ['0', '5']).any? | |
end | |
# Here is the random number we're going to try this time. | |
rnd | |
else | |
ARGV[0].to_i | |
end | |
# Initial check. | |
per(n, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment