Advertisement
Guest User

Untitled

a guest
Mar 5th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import itertools
  2.  
  3. iterations = 0
  4. highest_value = 0
  5. winning_strings = []
  6. current_value = 0
  7.  
  8. chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '/', '+', '-']
  9.  
  10. #perms = itertools.product(chars, repeat=len(chars))
  11. perms = itertools.permutations(chars, len(chars))
  12.  
  13. for arr in perms:
  14.     iterations += 1
  15.     current_string = ''.join(arr)
  16.  
  17.     if iterations % 500000 == 0:
  18.         print "%d %s %d" % (iterations, winning_strings[0], highest_value)
  19.  
  20.     try:
  21.         current_value = eval(current_string)
  22.     except SyntaxError:
  23.         pass
  24.  
  25.     if current_value > highest_value:
  26.         highest_value = current_value
  27.         winning_strings = [current_string]
  28.  
  29.     elif current_value == highest_value:
  30.         winning_strings.append(current_string)
  31.  
  32. print iterations
  33. print highest_value
  34. print winning_strings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement