close
# 題目是 請找出符合下列公式的排列方式 # O/OO + O/OO + O/OO = 1 # 填上1~9,數字不可重複 from time import time t0 = time() def Try(ans): if (ans[0] * 1.0 / (ans[1] * 10 + ans[2]) + ans[3] * 1.0 / (ans[4] * 10 + ans[5]) + ans[6] * 1.0 / (ans[7] * 10 + ans[8])) == 1: print ans def F(s, lv): if lv == 0: Try(ans) return for (x, i) in enumerate(s): ans.insert(0, i) tmp = s[:] tmp.pop(x) F(tmp, lv-1) ans.pop(0) ans = [] orz = range(1, 10) F(orz, len(orz)) print time()-t0
全站熱搜
留言列表