Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- iterations = 0
- highest_value = 0
- winning_strings = []
- current_value = 0
- chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '/', '+', '-']
- #perms = itertools.product(chars, repeat=len(chars))
- perms = itertools.permutations(chars, len(chars))
- for arr in perms:
- iterations += 1
- current_string = ''.join(arr)
- if iterations % 500000 == 0:
- print "%d %s %d" % (iterations, winning_strings[0], highest_value)
- try:
- current_value = eval(current_string)
- except SyntaxError:
- pass
- if current_value > highest_value:
- highest_value = current_value
- winning_strings = [current_string]
- elif current_value == highest_value:
- winning_strings.append(current_string)
- print iterations
- print highest_value
- print winning_strings
Advertisement
Add Comment
Please, Sign In to add comment