Skip to content

Instantly share code, notes, and snippets.

@inertia186
Last active November 16, 2020 05:30
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 inertia186/9d00888ac1315cf955915e1869341c04 to your computer and use it in GitHub Desktop.
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)
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