Last active
August 29, 2015 14:22
-
-
Save tAkihiko/44abe86535f8d21bb73d to your computer and use it in GitHub Desktop.
1時間で解けなかったらプログラマ失格問題5をPythonで(再掲) ref: http://qiita.com/tAkihiko/items/13e78befd63ff0bf001d
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 as it | |
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
num_str = map(str, nums) | |
#ops = ["+", "-", "/", "*", ""] | |
ops = [" + ", " - ", ""] | |
opss = it.tee(ops, len(nums) - 1) | |
for op_c in it.product(*opss): | |
evl = num_str[0] | |
for idx, op in enumerate(op_c): | |
evl += op + num_str[idx+1] | |
rst = eval(evl) | |
if rst == 100: | |
print evl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment