Changeset 41
- Timestamp:
- 08/11/08 20:40:46 (5 months ago)
- Files:
-
- scripts/python/sudoku/4x4x4.py (modified) (2 diffs)
- scripts/python/sudoku/permutation.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
scripts/python/sudoku/4x4x4.py
r40 r41 1 1 # coding=UTF-8 2 # test sur des sudokus simplifiés ( 4 lignes de 4 colones définissant 4 cellules )2 # fonction recursives pour tourver les permutations d un ensemble 3 3 4 4 def isSudoku(sudokuNumber, sudokuList, permutationList): … … 43 43 return ret 44 44 45 # etape 1 : trouver les permutations 45 46 def findAllPermutations( set ,length=1): 47 # fonction recursive 48 ret=[set[0:len(set)-length+1]] 49 if len(set)>length: 50 ret=[] 51 for x in set: 52 subset = [] 53 subset.extend( set ) 54 subset.remove( x ) 55 permut = findAllPermutations( subset ,length) 56 #print permut 57 for z in permut: 58 line=[x] 59 line.extend(z) 60 ret.append(line) 61 return ret 62 63 # initialisation 46 64 set=[1,2,3,4] 47 rotateAllSet={} 48 permutation=0 49 for x in set: 50 subset1=[] 51 subset1.extend(set) 52 subset1.remove(x) 53 for y in subset1: 54 subset2=[] 55 subset2.extend(subset1) 56 subset2.remove(y) 57 for z in subset2: 58 subset3=[] 59 subset3.extend(subset2) 60 subset3.remove(z) 61 rotateAllSet[permutation]=[x,y,z,subset3[0]] 62 permutation+=1 65 allPermutations=findAllPermutations(set) 66 allPermutationsDict={} 67 permut=0 68 for x in allPermutations: 69 allPermutationsDict[permut]=x 70 permut+=1 71 #print x 72 allSudokus=findAllPermutations(allPermutationsDict.keys(),20) 73 allSudokusDict={} 74 permut=0 75 for x in allSudokus: 76 allSudokusDict[permut]=x 77 permut+=1 78 #print x 63 79 64 allSudokus={} 65 permutation=0 66 # etape 2 : créer les sudokus possibles 255024 possibilitées 67 for x in rotateAllSet.keys(): 68 subset1=[] 69 subset1.extend(rotateAllSet) 70 subset1.remove(x) 71 for y in subset1: 72 subset2=[] 73 subset2.extend(subset1) 74 subset2.remove(y) 75 for z in subset2: 76 subset3=[] 77 subset3.extend(subset2) 78 subset3.remove(z) 79 for v in subset3: 80 allSudokus[permutation]=[x,y,z,v] 81 permutation+=1 80 count=1 81 for x in allSudokusDict.keys(): 82 if isSudoku(x, allSudokusDict, allPermutations): 83 print str(count)+". grille numero "+str(x) 84 for z in allSudokusDict[x]: 85 print str(allPermutationsDict[z]) 86 print "---------------------------------" 87 count+=1 88 89 print "nombre de grilles generees : "+str(len(allSudokusDict)) 82 90 83 91 84 92 85 count=186 for x in allSudokus.keys():87 rotateAllSetSet=[]88 for z in rotateAllSet.keys():89 rotateAllSetSet.append(rotateAllSet[z])90 if isSudoku(x, allSudokus, rotateAllSetSet):91 #print "---------------------------------"92 print str(count)+". Sudoku numero "+str(x)93 for z in allSudokus[x]:94 print str(rotateAllSet[z])95 print "---------------------------------"96 count+=197 98 99 print "nombre de grilles generees : "+str(len(allSudokus))100
