Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created August 24, 2021 07:24
Show Gist options
  • Save jonelf/6e616aaca2ca5c101821fa8792e73b50 to your computer and use it in GitHub Desktop.
Save jonelf/6e616aaca2ca5c101821fa8792e73b50 to your computer and use it in GitHub Desktop.
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