Last active
August 29, 2015 14:21
-
-
Save tAkihiko/446df40339688921629d to your computer and use it in GitHub Desktop.
1時間で解けなかったらプログラマ失格問題5をPythonで ref: http://qiita.com/tAkihiko/items/07ede10063ef1c5d7415
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