Created
January 4, 2014 04:38
-
-
Save tos-kamiya/8251784 to your computer and use it in GitHub Desktop.
My first program in 2014!
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 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