# 胡闹

## 我的思路

$((AB)C)D$
$(AB)(CD)$
$A((BC)D)$
$(A(BC))D$
$A(B(CD))$

## 结果

$1,14,16,12$这四个数算出来的是 $log_{1+log_{14!}16!}12$，是$3.12014$ 左右，还是有一定差距。

## 代码

from math import *
from itertools import permutations

pi = acos(-1)
global minn,ans
minn = 100000
ans=''

def fac(n):
res=1
if n>=100 or n<0 or abs(n-int(n))>1e-6:
return 100000000
for i in range(1,int(n)+1):
res=res*i
return res

try:
if op == 0:
return '(' + a + '+' + b + ')'
elif op == 1:
return '(' + a + '-' + b + ')'
elif op == 2:
return '(' + a + '*' + b + ')'
elif op == 3 and eval(b)!=0:
return '(' + a + '/' + b + ')'
elif op == 3:
return '(-10000000000)'
elif op == 4 and eval(a)!=0 and (abs(eval(b))<50 and abs(eval(a))<999999) and \\
isinstance(eval(a)**eval(b),complex)==False:
return '(' + a + '**' + b + ')'
# elif op==4 and eval(b)<0 and eval(b)>-50 and abs(eval(a))>1/999999 and abs(eval(a))<999999:
#     return '(' + a + '**' + b + ')'
elif op==4:
return '(-10000000000)'
elif op == 5 and eval(b)!=1 and eval(b)>0 and eval(a)>0 :
return '(log(' + a + ',' + b + '))'
else :
return '(-10000000000)'
except:
print(eval(a),eval(b),op)

def unary(a,op):
if op == 0 :
return a
else :
return '(fac('+a+'))'

def update(str):
# print(str)
now_ans = eval(str)
if(now_ans>4 or now_ans<3):
return
print(str)
print(now_ans)
global minn,ans
if abs(now_ans - pi) < abs(minn - pi):
minn = now_ans
ans = str

def Up(str):
update(unary(str,0))
update(unary(str,1))

def calc(ls):
print(ls)
for i in range(6):
for j1 in range(2):
for j2 in range(2):
for k in range(6):
for l in range(2):
for m in range(6):
for n in range(2):
Up(tmp3)

for i in range(6):
for j1 in range(2):
for j2 in range(2):
tmp1 = dyadic(unary(ls[0], j1), unary(ls[1], j2), i)
for k in range(6):
for l1 in range(2):
for l2 in range(2):
tmp2 = dyadic(unary(ls[2],l1), unary(ls[3], l2), k)
for m in range(6):
Up(tmp3)
# print("jbsm")
for i in range(6):
for j1 in range(2):
for j2 in range(2):
tmp1 = dyadic(unary(ls[1], j1), unary(ls[2], j2), i)
for k in range(6):
for l in range(2):
tmp2 = dyadic(tmp1, unary(ls[3], l), k)
for m in range(6):
for n in range(2):
Up(tmp3)

for i in range(6):
for j1 in range(2):
for j2 in range(2):
tmp1 = dyadic(unary(ls[1], j1), unary(ls[2], j2), i)
for k in range(6):
for l in range(2):
for m in range(6):
for n in range(2):
tmp3 = dyadic(tmp2, unary(ls[3], n), m)
Up(tmp3)

for i in range(6):
for j1 in range(2):
for j2 in range(2):
tmp1 = dyadic(unary(ls[2], j1), unary(ls[3], j2), i)
for k in range(6):
for l in range(2):
tmp2 = dyadic(unary(ls[1], l), tmp1, k)
for m in range(6):
for n in range(2):
Up(tmp3)

def main():
number=['1','12','14','16']
for i in permutations(number):
calc(i)

print(ans)
print(eval(ans))

main()


posted @ 2020-03-15 13:43  小飞淙的云端  阅读(92)  评论(0编辑  收藏