Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def all_combs(L, way):
- if len(L) == 1:
- if L[0] == 10:
- print way
- for i in xrange(len(L)):
- for j in xrange(i + 1, len(L)):
- for op in ["+", "/", "-", "*"]:
- try:
- new_L = [L[t] for t in xrange(len(L)) if t not in [i, j]] + [eval(str(L[i])+op+str(L[j]))]
- all_combs(new_L, way + [(L[i],op, L[j])] )
- new_L = [L[t] for t in xrange(len(L)) if t not in [i, j]] + [eval(str(L[j])+op+str(L[i]))]
- all_combs(new_L, way + [(L[j], op, L[i])])
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement