# 2021-01-22 MATH 3600 3n+1 problem

## 225 days ago by calkin

Further investigations of the 3n+1 problem

def g(n): if n.is_integer() and n>0: if n==1: return(0) elif is_odd(n): return((3*n+1)/2) else: return(n/2) else: return("Please enter a positive integer!")
g(4)
 2 2
g(7)
 11 11
N=1000 n=ZZ.random_element(1, N) print(n)
 990 990

Tossing a fair coin $M$ times: how many heads to we expect to see?

The probability that we get exactly $k$ heads is

$\binom{M}{k} 2^{-M}$

M=2000 L=[1.*binomial(M,k)*2^(-M) for k in srange(M+1) ]
list_plot(L) L
 0.246093750000000 0.246093750000000
hailstone=[[1,0]] champions=[] max_value_seen=3 for i in srange(2,10001): stepcounter=0 n=i while n> 1: n=g(n) stepcounter+=1 if stepcounter> max_value_seen: max_value_seen = stepcounter champions.append([i,max_value_seen]) hailstone.append([i,stepcounter])
A=list_plot(hailstone)
B=plot(2.*log(x)/log(4/3.),x,1,10000)
show(A+B) rand(10)
 Traceback (click to the left of this block for traceback) ... NameError: name 'rand' is not defined Traceback (most recent call last): File "", line 1, in File "_sage_input_4.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cmFuZCgxMCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in File "/tmp/tmpukTrBq/___code___.py", line 3, in exec compile(u'rand(_sage_const_10 ) File "", line 1, in NameError: name 'rand' is not defined
import randrange
 Traceback (click to the left of this block for traceback) ... ImportError: No module named randrange Traceback (most recent call last): File "", line 1, in File "_sage_input_5.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW1wb3J0IHJhbmRyYW5nZQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in File "/tmp/tmpVFfjWX/___code___.py", line 2, in exec compile(u'import randrange File "", line 1, in ImportError: No module named randrange
from sage.misc.prandom import randrange
randrange(1000)
 787 787