Using each of the digits 1 to 9 exactly once, and the standard arithmetic operators, +,-, *, /, and, () as many times as required; come up with a value that is closest to φ.
This means, minimizing abs(V - φ), where V is the obtained value and, abs is the
absolute function.
(I) Use only the individual digits. Concatenations like (98-34)/(1*2) - (56/7) are NOT allowed.
(II) Concatenations are allowed.
Note: φ is the golden ratio or the golden mean.
Best so far: 34/21 - 7/6895 with error= 1.5981286718425025e-06
Starting with the template of 34/21 - a/bcde where {a,b,c,d,e} are {5,6,7,8,9}
I found the closest solution of that particular format as:
34/21 - 7/6895 = 1.618032390621223 error= 1.5981286718425025e-06
Other templates based on Fibonacci ratios not as close:
Starting with a format of 13/8 - ab/cdef :
13/8 - 52/7469 = 1.6180378899451064 error= 3.9011952115419746e-06 which was not quite as good
And the best of 8/5 - ab/cdefg was
8/5 + 97/12346 = 1.6078567957233112 error= 0.010177193026583709 which is nowhere near as close
------------
sample code; modified for each variation of the template
frac = 34/21
others = '56789'
others = [int(a) for a in others]
smallerr = 1
from itertools import permutations
for p in permutations(others):
errorterm = p[0]/(1000*p[1] + 100*p[2] + 10*p[3] + p[4])
err = abs(phi - (frac - errorterm))
if err < smallerr:
guess = frac - errorterm
best = p
print('34/21 - {}/{}{}{}{} = {} error= {}'.format(p[0],p[1],p[2],p[3],p[4],guess, err))
smallerr = err
|
Posted by Larry
on 2023-02-08 10:37:41 |