fork download
  1. import copy, itertools
  2. numbers = list("123456789")
  3. operators = list("+-*/")
  4.  
  5. for i in range(1, 9):
  6. for j in operators:
  7. temp = copy.deepcopy(numbers)
  8. temp.insert(i, j)
  9. if eval(''.join(temp)) == 100:
  10. print ''.join(temp) + "=100"
  11.  
  12. for i in range(1, 9):
  13. for j in range(i+2, 10):
  14. for k, l in itertools.product(operators, operators):
  15. temp = copy.deepcopy(numbers)
  16. temp.insert(i, k)
  17. temp.insert(j, l)
  18. if eval(''.join(temp)) == 100:
  19. print ''.join(temp) + "=100"
  20.  
  21. for i in range(1, 9):
  22. for j in range(i+2, 10):
  23. for k in range(j+2, 11):
  24. for l, m, n in itertools.product(operators, operators, operators):
  25. temp = copy.deepcopy(numbers)
  26. temp.insert(i, l)
  27. temp.insert(j, m)
  28. temp.insert(k, n)
  29. if eval(''.join(temp)) == 100:
  30. print ''.join(temp) + "=100"
  31.  
Success #stdin #stdout 0.08s 9024KB
stdin
Standard input is empty
stdout
123-45-67+89=100