ref : http://blog.readiz.com/112
두번째는 그냥 가능한 전체 리스트를 만들어서 검사.
quizS2.py
1 from quiz import prettyPrint 2 3 def isMatchCase((a,b,c,d,e,f,g,h,i)): 4 tmp = (a*10+b)*c 5 6 if tmp>98: 7 return False 8 9 if not tmp == d*10+e: 10 return False 11 12 if not tmp+f*10+g == h*10+i: 13 return False 14 15 prettyPrint((a,b,c,d,e,f,g,h,i)) 16 return True 17 18 def getAllAvailableList(allRange=range(1, 10)): 19 iGotIt = False 20 l = [] 21 for a in filter(lambda x: x not in l, allRange): 22 l.append(a) 23 for b in filter(lambda x: x not in l, allRange): 24 l.append(b) 25 for c in filter(lambda x: x not in l, allRange): 26 l.append(c) 27 for d in filter(lambda x: x not in l, allRange): 28 l.append(d) 29 for e in filter(lambda x: x not in l, allRange): 30 l.append(e) 31 for f in filter(lambda x: x not in l, allRange): 32 l.append(f) 33 for g in filter(lambda x: x not in l, allRange): 34 l.append(g) 35 for h in filter(lambda x: x not in l, allRange): 36 l.append(h) 37 for i in filter(lambda x: x not in l, allRange): 38 #retList.append((a,b,c,d,e,f,g,h,i)) 39 if isMatchCase((a,b,c,d,e,f,g,h,i)): 40 iGotIt = True 41 l.remove(h) 42 l.remove(g) 43 l.remove(f) 44 l.remove(e) 45 l.remove(d) 46 l.remove(c) 47 l.remove(b) 48 l.remove(a) 49 return iGotIt 50 51 if __name__ == '__main__': 52 if not getAllAvailableList(): 53 print "Cannot find numbers set(s)."
댓글