Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = [0 for i in range(11)]
- def check_and_print():
- #init
- s = 0
- sign = 0
- stack = []
- #calculate each element generated and push them into stack
- for i in range(0,9):
- if (x[i] == 0):
- s = s * 10 + i + 1
- else:
- if (s != 0):
- stack.append(s*sign)
- s = i + 1
- sign = x[i]
- stack.append(int(s)*sign)
- #if sum = 10 then print
- if (sum(stack) == 100):
- for i in stack:
- print ("%+d" %(i),end= "")
- print()
- #solve the problem using recursion
- def solve(i):
- for j in range(-1,2):
- x[i] = j
- if (x[0] == 0):
- continue
- if (i == 8):
- check_and_print()
- else:
- solve(i + 1)
- x[i] = 0
- solve(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement