I've been trying to work on solving or at least understanding the 3n+1 problem. The program tries numbers 1 by 1 until they reach the infamous 4-->2-->1 loop. And then tries the next number. The goal of the program is to do this until I reach a number that does not find this inevitable loop. If possible.
I keep having the same error. When I reach number 996, I end up with the error:
"RecursionError: maximum recursion depth exceeded while calling a Python object"
on=True
import time
x=0
def loop():
global x
x=x+1
time.sleep(0.01)
print("new: "+str(x))
n=x
while on==True:
if (n%2==0):
n=n/2
else:
n=3*n+1
print(n)
if n==1:
loop()
loop()
This is my code. I have tried importing os and using the os.system('cls') command which should work since I'm on windows but it hasn't even functioned.
Even only printing the new numbers rather than all the numbers makes it stop at the same number. Which tells me it's not just a character limit.