Guest User

Untitled

a guest
Nov 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. def main():
  2. import itertools
  3. digits = ['1','2','3','4','5','6','7','8','9']
  4. operators = ['+', '-', '']
  5.  
  6. for combination in itertools.product(operators, repeat=8): # combinations of 8 operators
  7. # Create all possible combinations of digits and operators as lists
  8. statement = [None] * (len(digits) + len(combination))
  9. statement[::2] = digits
  10. statement[1::2] = combination
  11.  
  12. if eval(''.join(statement)) == 100: # concatenate the elements
  13. print(''.join(statement))
  14.  
  15.  
  16. if __name__ == '__main__':
  17. main()
Add Comment
Please, Sign In to add comment