f = open("summatest.01.sis", "rt")
n = (f.readline())
jada_elemendid = f.readline().strip().split(' ')
otstav_summa = f.readline().strip()
f.close()
# Valjund
vfal = file("sum.val", "w")
lmargid = []
def otsi(k):
if (k < n):
print n
k = k + 1
lmargid.append("+")
if otsi(k):
return True
lmargid.append("-")
print lmargid
else:
z = jada_elemendid[0]
for i in range(n + 1):
if lmargid.index(i) == "+":
z = z + jada_elemendid.index(i)
else:
z = z - jada_elemendid.index(i)
if z == otstav_summa:
vfal.write(jada_elemendid[0])
for ii in xrange(n + 1):
vfal.write(jada_elemendid(ii))
vfal.write("=" + z)
return True
return False
if not otsi(0):
vfal.write("EI OLE")
File "summa.py", line 17, in otsi
if (k < n):
RuntimeError: maximum recursion depth exceeded in cmp
Input:
summa.sis
3
15 25 30
10
Output:
summa.val
15+25-30=10