Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- import itertools
- digits = ['1','2','3','4','5','6','7','8','9']
- operators = ['+', '-', '']
- for combination in itertools.product(operators, repeat=8): # combinations of 8 operators
- # Create all possible combinations of digits and operators as lists
- statement = [None] * (len(digits) + len(combination))
- statement[::2] = digits
- statement[1::2] = combination
- if eval(''.join(statement)) == 100: # concatenate the elements
- print(''.join(statement))
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment