Skip to content

Instantly share code, notes, and snippets.

@bensmith83
Created January 2, 2020 02:15
Show Gist options
  • Save bensmith83/5c50a30b43dd9ed674c8b3f72715f1ea to your computer and use it in GitHub Desktop.
Save bensmith83/5c50a30b43dd9ed674c8b3f72715f1ea to your computer and use it in GitHub Desktop.
Quick python to calculate collatz conjecture numbers and the amount of steps to get there.
start = 3
most_steps_num = 0
most_steps_steps = 0
while True:
#number = input("enter a number to test the Collatz Conjecture\n")
#number = int(number)
#orig = number
number = start
steps = 0
while number > 1:
if number % 2 == 0:
number = number / 2
else:
number = number * 3 + 1
steps = steps + 1
#print(number)
if steps > most_steps_steps:
most_steps_num = start
most_steps_steps = steps
print("[*] Number: {:^11} took {:^7} steps\tHighest steps for {:^11}: {:^7}".format(start, steps, most_steps_num, most_steps_steps))
start = start + 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment