Created
February 20, 2022 03:12
-
-
Save kepstein/74a8da9bbac091d3b84068c2adbdf66e to your computer and use it in GitHub Desktop.
3x + 1 Math problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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