(Python) from itertools import product
def qx(arr): #given continued fraction,
..qx = 0
..for i in range(1, len(arr)): #generate ?(x)/2
....qx += (-1)**(i+1) / 2**sum(arr[:i+1])
..ratio = arr[-1]
..for i in range(len(arr)-2, -1, -1): #generate x
....ratio = arr[i] + 1/ratio
..return 2*qx - ratio, ratio #subtract
arr = [0, 1]
for k in range(1, 19):
..cap = [0, ()] #current best branch
..for tag in product(range(1, 21), repeat=4):
....res = qx(arr + list(tag)) #test a branch, record if best
....if res[0] > cap[0]: cap = [res[0], tag, res[1]]
..print(cap) #print current ?(x)-x, best branch, current x
..arr.append(cap[1][0]) #go down the branch
|