Created
August 24, 2021 07:24
-
-
Save jonelf/6e616aaca2ca5c101821fa8792e73b50 to your computer and use it in GitHub Desktop.
Got inspired by https://www.youtube.com/watch?v=094y1Z2wpJg
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
def collatzConjecture(n) | |
steps = 0 | |
max = 0 | |
until n == 1 | |
steps += 1 | |
n = n.odd? ? n * 3 + 1 : n / 2 | |
max = n if max < n | |
end | |
[steps, max] | |
end | |
n = 1 | |
max_steps = 0 | |
max_value = 0 | |
loop do | |
steps, max = collatzConjecture(n) | |
if max_steps < steps | |
max_steps = steps | |
puts "#{n}: New maximum number of steps is #{max_steps}" | |
sleep(0.5) | |
end | |
if max_value < max | |
max_value = max | |
puts "#{n}: New highest number is #{max_value}" | |
end | |
# puts "#{n}: #{steps} #{max}" | |
n += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment