参考知乎:知乎

http://www.zhihu.com/question/24905007/answer/29414497

原答案已被作者删除

 

 1 from itertools import *
 2 
 3 impossible = {'13': '2', 
 4               '46': '5', 
 5               '79': '8', 
 6               '17': '4', 
 7               '28': '5', 
 8               '39': '6', 
 9               '19': '5', 
10               '37': '5',
11               '31': '2',
12               '64': '5',
13               '97': '8',
14               '71': '4',
15               '82': '5',
16               '93': '6',
17               '91': '5',
18               '73': '5'}
19 
20 def counts():
21     iterlst = chain(*(permutations('123456789', i) for i in range(4, 10)))
22     count = 0
23     for i in iterlst:
24         stri = ''.join(i)
25         for k, v in impossible.items():
26             if k in stri and v not in stri[:stri.find(k)]:
27                 break
28         else:
29             count += 1
30     return count
31 
32 print(counts())

 

posted on 2017-05-04 00:29  MicN  阅读(209)  评论(0编辑  收藏  举报