Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Created February 3, 2020 14:21
Show Gist options
  • Save martintrojer/eeebbff19aa9facbabe1776cb073e134 to your computer and use it in GitHub Desktop.
Save martintrojer/eeebbff19aa9facbabe1776cb073e134 to your computer and use it in GitHub Desktop.
import itertools
print("Klara is the best")
numbers = map(float,range(1,10))
ops = ['+','-','*','/']
all_ops = list(itertools.product(ops,repeat=8))
print('There are {} different ways to order {} between {}'
.format(len(all_ops), ops, numbers))
def eq2str(eq):
return ''.join(map(str,eq))
good = []
for o in all_ops:
eq = list(sum(zip(numbers,o),())) + [9]
if eval(eq2str(eq)) == 100.0:
good = good + [eq]
print('Number of equations {}'.format(len(good)))
for i in good:
print(eq2str(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment