Skip to content

Instantly share code, notes, and snippets.

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