Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Created January 4, 2014 04:38
Show Gist options
  • Save tos-kamiya/8251784 to your computer and use it in GitHub Desktop.
Save tos-kamiya/8251784 to your computer and use it in GitHub Desktop.
My first program in 2014!
import sys
nums = "123456789"
opes = ["", "+", "-", "*", "/"]
def gen(remaining_nums, ex):
ex = ex + remaining_nums[0]
remaining_nums = remaining_nums[1:]
if not remaining_nums:
yield ex
else:
for o in opes:
e = ex + o
for y in gen(remaining_nums, e):
yield y
for ex in gen(nums, ""):
if eval(ex) == 2014:
sys.stdout.write("%s\n" % ex)
elif eval("-" + ex) == 2014:
sys.stdout.write("-%s\n" % ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment