Created
February 3, 2020 14:21
-
-
Save martintrojer/eeebbff19aa9facbabe1776cb073e134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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