Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. def all_combs(L, way):
  2.     if len(L) == 1:
  3.         if L[0] == 10:
  4.             print way
  5.     for i in xrange(len(L)):
  6.         for j in xrange(i + 1, len(L)):
  7.             for op in ["+", "/", "-", "*"]:
  8.                 try:
  9.                     new_L = [L[t] for t in xrange(len(L)) if t not in [i, j]] + [eval(str(L[i])+op+str(L[j]))]
  10.                     all_combs(new_L, way + [(L[i],op, L[j])] )
  11.                     new_L = [L[t] for t in xrange(len(L)) if t not in [i, j]] + [eval(str(L[j])+op+str(L[i]))]
  12.                     all_combs(new_L, way + [(L[j], op, L[i])])
  13.                  except:
  14.                     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement