Hailstone

2256 days ago by calkin

A=matrix(2,2,[mod(1,10),mod(1,10),mod(1,10),mod(0,10)]) 
       
print(A) 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'A' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_3.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cHJpbnQoQSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpjjmKgt/___code___.py", line 2, in <module>
    exec compile(u'print(A)
  File "", line 1, in <module>
    
NameError: name 'A' is not defined
type(A[0,0]) 
       
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
print(A^20) 
       
[6 5]
[5 1]
[6 5]
[5 1]
fibonacci(21) 
       
10946
10946
def hailstone(n): if type(n) != Integer: print("Dummy!") # Tell the user that he is an idiot for running this on a non-integer return(1/2) elif n<=0: print("Please use a positive value") #The user is still an idiot return(-1) elif is_even(n): return(Integer(n/2)) else: return(3*n+1) 
       
hailstone(n) 
       
Dummy!
1/2
Dummy!
1/2
n=range(5)[3] print(n) print(type(n)) print(type(3)) 
       
3
<type 'int'>
<type 'sage.rings.integer.Integer'>
3
<type 'int'>
<type 'sage.rings.integer.Integer'>
hailstone(1) 
       
4
4
hailstone_list=[0,0] for n in srange(2,10000): count=0 while n>1: count+=1 n=hailstone(n) #print(n,count) hailstone_list.append(count) #print(hailstone_list) 
       
hailstone_list[49999] 
       
88
88
type(hailstone(10)) 
       
<type 'sage.rings.integer.Integer'>
<type 'sage.rings.integer.Integer'>
list_plot(hailstone_list) 
       
hailstone_even=[hailstone_list[2*i] for i in srange(len(hailstone_list)/2)] 
       
hailstone_odd=[hailstone_list[2*i+1] for i in srange(len(hailstone_list)/2)] 
       
len(hailstone_odd) 
       
5000
5000
A=list_plot(hailstone_odd,color='red') B=list_plot(hailstone_even,color='blue') show(A+B) 
       
max(hailstone_list) 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'hailstone_list' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_4.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bWF4KGhhaWxzdG9uZV9saXN0KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpjrglcB/___code___.py", line 2, in <module>
    exec compile(u'max(hailstone_list)
  File "", line 1, in <module>
    
NameError: name 'hailstone_list' is not defined