Skip to content

Instantly share code, notes, and snippets.

@kepstein
Created February 20, 2022 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kepstein/74a8da9bbac091d3b84068c2adbdf66e to your computer and use it in GitHub Desktop.
Save kepstein/74a8da9bbac091d3b84068c2adbdf66e to your computer and use it in GitHub Desktop.
3x + 1 Math problem
num = 27
steps = 0
# while steps < 30: # use this while logic to show that it continuously loops 4,2,1. The number 30 can be changed to any arbitrary number
while num != 1:
if num % 2 != 0:
num = num * 3 + 1
else:
num = num / 2
print(num)
steps += 1
print(steps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment