Skip to content

Instantly share code, notes, and snippets.

@vaxyzek
Created January 12, 2017 22:40
Show Gist options
  • Save vaxyzek/ce8f7e12f5b3ae5a63d89f941b9c3c6d to your computer and use it in GitHub Desktop.
Save vaxyzek/ce8f7e12f5b3ae5a63d89f941b9c3c6d to your computer and use it in GitHub Desktop.
import itertools, math
digits = "123456789"
ops = ['+','-','/','*','']
answers = {}
for p in itertools.product(ops, ops, ops, ops, ops, ops, ops, ops):
exp = digits[0]
for i in range(len(p)):
exp += p[i] + digits[i + 1]
res = eval(exp)
if res == math.floor(res):
answers[int(res)] = exp
for k in sorted(answers.keys()):
if k > 0:
print(k, answers[k])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment