Extra problem

1629 days ago by hagenbr

def expand( given, maxsteps=30 ): a0 = floor( given ) remainder = given - a0 expansion = [a0] steps = 1 while ((remainder != 0) & (steps < maxsteps)): recip = 1/remainder newa = floor( recip ) expansion = expansion + [newa] remainder = recip - newa steps = steps + 1 print expansion 
       
def help_me_reassemble( a_list ): p_list = [0, 1] q_list = [1, 0] for j in range(2, len(a_list) + 2 ): p_list = p_list + [ a_list[j-2] * p_list[j-1] + p_list[j-2] ] q_list = q_list + [ a_list[j-2] * q_list[j-1] + q_list[j-2] ] print j+1, print "th approximation", print p_list[j], print "/", print q_list[j], print " roughly ", print n( p_list[j] / q_list[j] ) 
       
N = 5688029 E = 4694867 
       
r1 = n( N/E, digits = 20) print r1 
       
1.2115420948026855713
1.2115420948026855713
expand (r1) 
       
[1, 4, 1, 2, 1, 1, 1, 101, 6, 1, 1, 10, 1, 5, 53896285, 18, 13, 14, 1,
1, 3, 11, 1, 1, 2, 27, 5, 2, 1, 6]
[1, 4, 1, 2, 1, 1, 1, 101, 6, 1, 1, 10, 1, 5, 53896285, 18, 13, 14, 1, 1, 3, 11, 1, 1, 2, 27, 5, 2, 1, 6]
help_me_reassemble([1, 4, 1, 2, 1, 1, 1, 101, 6, 1, 1, 10, 1, 5]) 
       
3 th approximation 1 / 1  roughly  1.00000000000000
4 th approximation 5 / 4  roughly  1.25000000000000
5 th approximation 6 / 5  roughly  1.20000000000000
6 th approximation 17 / 14  roughly  1.21428571428571
7 th approximation 23 / 19  roughly  1.21052631578947
8 th approximation 40 / 33  roughly  1.21212121212121
9 th approximation 63 / 52  roughly  1.21153846153846
10 th approximation 6403 / 5285  roughly  1.21154210028382
11 th approximation 38481 / 31762  roughly  1.21154209432655
12 th approximation 44884 / 37047  roughly  1.21154209517640
13 th approximation 83365 / 68809  roughly  1.21154209478411
14 th approximation 878534 / 725137  roughly  1.21154209480415
15 th approximation 961899 / 793946  roughly  1.21154209480242
16 th approximation 5688029 / 4694867  roughly  1.21154209480269
3 th approximation 1 / 1  roughly  1.00000000000000
4 th approximation 5 / 4  roughly  1.25000000000000
5 th approximation 6 / 5  roughly  1.20000000000000
6 th approximation 17 / 14  roughly  1.21428571428571
7 th approximation 23 / 19  roughly  1.21052631578947
8 th approximation 40 / 33  roughly  1.21212121212121
9 th approximation 63 / 52  roughly  1.21153846153846
10 th approximation 6403 / 5285  roughly  1.21154210028382
11 th approximation 38481 / 31762  roughly  1.21154209432655
12 th approximation 44884 / 37047  roughly  1.21154209517640
13 th approximation 83365 / 68809  roughly  1.21154209478411
14 th approximation 878534 / 725137  roughly  1.21154209480415
15 th approximation 961899 / 793946  roughly  1.21154209480242
16 th approximation 5688029 / 4694867  roughly  1.21154209480269
this = 1664197^19 % N print this 
       
1629486
1629486
tried all the possible d's and none worked... 
       
Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_34.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dHJpZWQgYWxsIHRoZSBkJ3MgYW5kIG5vbmUgd29ya2VkLi4u"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpsq1izA/___code___.py", line 2
    tried all the d's and none worked...
            ^
SyntaxError: invalid syntax