以任意的正整數 $a_1$ 開始, 產生 $a_2, a_3, \ldots$, 規則如下:
%pylab inline
def ice(a):
if a%2 == 0:
return a/2
else:
return 3*a+1
Populating the interactive namespace from numpy and matplotlib
k=23
L = [k]
while k != 1:
k = ice(k)
L.append(k)
plot(L)
[<matplotlib.lines.Line2D at 0x10682d610>]
L
[23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
def iceser(k):
L = [k]
while k != 1:
k = ice(k)
L.append(k)
plot(L)
iceser(1023)
from IPython.html.widgets import interact
interact(iceser, k=(2,200))