Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created August 24, 2021 07:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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