Skip to content

Instantly share code, notes, and snippets.

@terror
Created July 30, 2021 17:51
Show Gist options
  • Save terror/6e8c5a26c1d47abf6e1861951e17ddcd to your computer and use it in GitHub Desktop.
Save terror/6e8c5a26c1d47abf6e1861951e17ddcd to your computer and use it in GitHub Desktop.
# 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