Created
July 30, 2021 17:51
-
-
Save terror/6e8c5a26c1d47abf6e1861951e17ddcd to your computer and use it in GitHub Desktop.
This file contains 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
# The halting problem, will this program | |
# terminate or run forever? | |
def main(): | |
mx = j = - 1 | |
for i in range(1, int(input('N: ')) + 1): | |
# start at every number between [1, N] | |
steps = 0; curr = i | |
while curr != 1: | |
if curr & 1: | |
curr = (curr * 3) + 1 | |
else: | |
curr //= 2 | |
steps += 1 | |
print(f'{i} reached the end in {steps} steps.') | |
if steps > mx: | |
mx = steps; j = i | |
print(f'Max steps: {mx}, for number {j}.') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment