# -*- coding:utf-8 -*-
#[1,1,5,8]から10を作る
#『Nexus 7 : 10 Puzzle』――http://w...content-available-to-author-only...e.com/watch?v=JslkN8IulNA
def getope():
ope = ['+','-','*','/']
opelist = []
for x in ope:
for y in ope:
for z in ope:
#opes = unique([x,y,z])
opes = [x,y,z]
if(len(opes)==3):
opelist.append(opes)
return opelist
def getnum():
num = [1,1,5,8]
numlist=[]
enu = range(len(num))
for w in enu:
for x in enu:
for y in enu:
for z in enu:
nums = unique([w,x,y,z])
if(len(nums)==4):
numlist.append([str(float(num[a])) for a in nums])
return numlist
def getparent():
parlist=[]
parlist.append(['(',')','','','','','',''])
parlist.append(['(','','',')','','','',''])
parlist.append(['(','','','','',')','',''])
parlist.append(['(','','','','','','',')'])
parlist.append(['','','(',')','','','',''])
parlist.append(['','','(','','',')','',''])
parlist.append(['','','(','','','','',')'])
parlist.append(['','','','','(',')','',''])
parlist.append(['','','','','(','','',')'])
parlist.append(['','','','','','','(',')'])
return parlist
def unique(old_list):
new_list=[]
for i in old_list:
if i not in new_list:
new_list.append(i)
return new_list
def main():
numlist = getnum()
opelist = getope()
parlist = getparent()
for n in numlist:
for o in opelist:
for p in parlist:
syn = p[0] + n[0] + p[1] + o[0] +p[2]+ n[1] +p[3]+ o[1] +p[4] + n[2] +p[5]+ o[2] +p[6] + n[3] + p[7]
try:
a = eval(syn)
except ZeroDivisionError:
pass
if(a==10):
print(syn+' = 10')
if(__name__=='__main__'):
main()
IyAtKi0gY29kaW5nOnV0Zi04IC0qLQoKI1sxLDEsNSw4XeOBi+OCiTEw44KS5L2c44KLCiPjgI5OZXh1cyA3IDogMTAgUHV6emxl44CP4oCV4oCVaHR0cDovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmUuY29tL3dhdGNoP3Y9SnNsa044SXVsTkEKCmRlZiBnZXRvcGUoKToKCW9wZSA9IFsnKycsJy0nLCcqJywnLyddCglvcGVsaXN0ID0gW10KCWZvciB4IGluIG9wZToK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