diff --git a/README.md b/README.md index 77c7d0d..998b1f4 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ Tous les documents se trouvent ici avec la licence * `sudoku_grid.py` : module définissant une classe `SudokuGrid` pour représenter les grilles de Sudoku. * `sudoku_solver.py` : module définissant une fonction `solve` pour la résolution des grilles de Sudoku. +* `sudoku_mondrian.py` : module permettant de produire des images représentant des grilles de Sudoku colorées « à la Mondrian ». * `main1.py` : script de résolution d'une grille décrite en argument sur la ligne de commande. * `main2.py` : script de résolution d'une grille contenue dans un fichier. Les solutions sont affichées dans le terminal. * `main3.py` : script de résolution de toutes les grilles contenues dans un fichier. Les solutions sont inscrites dans un fichier. * `main4.py` : script de résolution d'une grille décrite sur la ligne de commande, et qui produit une image représentant la recherche des solutions. * `main5.py` : scripy de résolution d'une grille décrite sur la ligne de commande, qui visualise le remplissage progressif de la grille. +* `main6.py` : script produisant une représentation « à la Mondrian » d'une grille décrite sur la ligne de commande. * `bdd/sudokus.bdd` : un fichier texte contenant la description de 5000 grilles de Sudoku ayant toutes une seule solution. * `bdd/sudoku17.bdd` : un fichier texte contenant la description de 49151 grilles de Sudoku n'ayant que 17 cases remplis et ayant toutes une seule solution. @@ -24,9 +26,359 @@ Tous les documents se trouvent ici avec la licence ### Exemples d'utilisation +Tous les exemples qui suivent s'exécutent dans un terminal de commandes (shell). Ils ont tous été testés sur une machine Linux (Debian). Dans les exemples qui suivent, le symbole `$` désigne le prompt du terminal. Et les fichiers `main?.py` sont supposés avoir le droit d'exécution (si ce n'est pas le cas, il faut remplacer `./main?.py` par `python3 main?.py`. + +#### Résoudre une grille de Sudoku décrite sur la ligne de commande + + +Avec le script `main1.py` on peut résoudre toute grille de Sudoku décrite sur la ligne de commande. + +Une grille de Sudoku est décrite sur la ligne de commande par une succession de 81 caractères compris entre `0` et `9` (`0` pour une case vide). Les neuf premiers caractères représentent la première ligne de la grille, les neuf suivants la deuxième ligne, etc ... + +À titre d'exemples, avec la grille + + +-------+-------+-------+ + | 9 . 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | 5 . . | + +-------+-------+-------+ + +on obtient une seule solution + + $ ./main1.py 906028003040500001080900040600000070008206900030000005050003060100002080200870500 + Sudoku to solve + +-------+-------+-------+ + | 9 . 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | 5 . . | + +-------+-------+-------+ + Number of solution(s): 1 + -- + Solution 1 + +-------+-------+-------+ + | 9 1 6 | 4 2 8 | 7 5 3 | + | 3 4 2 | 5 6 7 | 8 9 1 | + | 7 8 5 | 9 3 1 | 2 4 6 | + +-------+-------+-------+ + | 6 2 9 | 3 4 5 | 1 7 8 | + | 5 7 8 | 2 1 6 | 9 3 4 | + | 4 3 1 | 7 8 9 | 6 2 5 | + +-------+-------+-------+ + | 8 5 7 | 1 9 3 | 4 6 2 | + | 1 9 4 | 6 5 2 | 3 8 7 | + | 2 6 3 | 8 7 4 | 5 1 9 | + +-------+-------+-------+ + -- + +Et avec la grille + + +-------+-------+-------+ + | 9 . 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | . . . | + +-------+-------+-------+ + +on obtient deux solutions + + $ ./main1.py 906028003040500001080900040600000070008206900030000005050003060100002080200870000 + Sudoku to solve + +-------+-------+-------+ + | 9 . 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | . . . | + +-------+-------+-------+ + Number of solution(s): 2 + -- + Solution 1 + +-------+-------+-------+ + | 9 1 6 | 4 2 8 | 7 5 3 | + | 3 4 2 | 5 6 7 | 8 9 1 | + | 7 8 5 | 9 3 1 | 2 4 6 | + +-------+-------+-------+ + | 6 2 9 | 3 4 5 | 1 7 8 | + | 5 7 8 | 2 1 6 | 9 3 4 | + | 4 3 1 | 7 8 9 | 6 2 5 | + +-------+-------+-------+ + | 8 5 7 | 1 9 3 | 4 6 2 | + | 1 9 4 | 6 5 2 | 3 8 7 | + | 2 6 3 | 8 7 4 | 5 1 9 | + +-------+-------+-------+ + -- + Solution 2 + +-------+-------+-------+ + | 9 1 6 | 4 2 8 | 7 5 3 | + | 3 4 2 | 5 6 7 | 8 9 1 | + | 7 8 5 | 9 3 1 | 2 4 6 | + +-------+-------+-------+ + | 6 2 9 | 3 5 4 | 1 7 8 | + | 5 7 8 | 2 1 6 | 9 3 4 | + | 4 3 1 | 7 8 9 | 6 2 5 | + +-------+-------+-------+ + | 8 5 7 | 1 9 3 | 4 6 2 | + | 1 9 3 | 6 4 2 | 5 8 7 | + | 2 6 4 | 8 7 5 | 3 1 9 | + +-------+-------+-------+ + -- + +Enfin avec la grille + + +-------+-------+-------+ + | 9 7 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | 5 . . | + +-------+-------+-------+ + +on n'obtient aucune solution + + $ ./main1.py 976028003040500001080900040600000070008206900030000005050003060100002080200870500 + Sudoku to solve + +-------+-------+-------+ + | 9 7 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | 5 . . | + +-------+-------+-------+ + Number of solution(s): 0 + -- + +#### Résoudre une grille de Sudoku décrite dans un fichier texte + +Les grilles de Sudoku peuvent être décrites dans des fichiers texte. C'est le cas des deux fichiers `bdd/sudokus.bdd` et `bdd/sudoku17.bdd` qui contiennent chacun plusieurs milliers de grilles de Sudoku. Ces grilles sont décrites comme précédemment par des chaînes de 81 caractères compris entre `0` et `9`. Une description peut être précédée par un `:` et dans ce cas les caractères qui précèdent sont ignorés. + +Voici comment résoudre la première grille du fichier `bdd/sudokus.bdd` + + $ ./main2.py bdd/sudokus.bdd 0 + Sudoku to solve + +-------+-------+-------+ + | 4 9 . | . . 1 | . . 7 | + | . . . | . 4 5 | . 3 . | + | 3 8 2 | 6 . . | . 5 . | + +-------+-------+-------+ + | . . 3 | . 7 . | 4 . 1 | + | 8 . . | 9 . 2 | . . 5 | + | 9 . 7 | . 3 . | 6 . . | + +-------+-------+-------+ + | . 3 . | . . 6 | 5 2 9 | + | . 2 . | 8 5 . | . . . | + | 5 . . | 7 . . | . 1 3 | + +-------+-------+-------+ + Number of solution(s): 1 + -- + Solution 1 + +-------+-------+-------+ + | 4 9 5 | 3 8 1 | 2 6 7 | + | 6 7 1 | 2 4 5 | 9 3 8 | + | 3 8 2 | 6 9 7 | 1 5 4 | + +-------+-------+-------+ + | 2 6 3 | 5 7 8 | 4 9 1 | + | 8 1 4 | 9 6 2 | 3 7 5 | + | 9 5 7 | 1 3 4 | 6 8 2 | + +-------+-------+-------+ + | 7 3 8 | 4 1 6 | 5 2 9 | + | 1 2 9 | 8 5 3 | 7 4 6 | + | 5 4 6 | 7 2 9 | 8 1 3 | + +-------+-------+-------+ + -- + +#### Résoudre toutes les grilles décrites dans un fichier + +Le script `main3.py` permet de résoudre toutes les grilles décrites dans un fichier dont on donne le nom dans la ligne de commandes. + + $ ./main3.py bdd/sudokus.bdd + +L'exécution de cette commande n'affiche rien. Elle se contente de produire un fichier dont le nom est celui passé en argument suivi de l'extension `.sol`. Chaque ligne de ce fichier contient + +1. les 81 caractères de la grille d'origine (avec éventuellement quelques mentions qui la précèdent) suivis d'un `:` ; +2. le caractère `y` si la solution est unique ou le caractère `n` s'il n'y a aucune ou plus d'une solution ; +3. les solutions séparées par des `:`. + +Voici les trois premières lignes du fichier `bdd/sudokus.bdd.sol` produit par la commande précédente : + + easy:490001007000045030382600050003070401800902005907030600030006529020850000500700013:y:495381267671245938382697154263578491814962375957134682738416529129853746546729813 + fiendish:020500730000490050500000000019207005060000070400908120000000006080029000096005040:y:921586734637491258548372691819237465263154879475968123152743986384629517796815342 + hard:050008460004000038000030107000920003020000050700086000208090000460000900015700080:y:352178469174269538896435127581924673629317854743586291238691745467853912915742386 + +Toutes les grilles sont résolues #### Visualiser la recherche de solution avec le script `main4.py` -Pour la grille ci-dessous (grille de la ligne 43 (en numérotant à partir de 0) du fichier `bdd/sudokus.bdd`) + +Pour utiliser ce script il est supposé que la suite logicielle [graphviz](https://graphviz.org/) est installée. + +Le script `main4.py` permet de produire une image représentant l'arbre de recherche des solutions parcouru par l'algorithme de résolution mis en œuvre dans le module `sudoku_solver`. + +Son utilisation nécessite deux arguments sur la ligne de commande : + +1. une chaîne de 81 caractères représentant la grille à résoudre +2. un nom pour les deux fichiers qui seront produits. Ce nom sera automatiquement complété de l'extension `.dot` pour l'un de ces deux fichiers qui contiendra une description de l'arbre dans le langage de description de graphes de `graphviz`. L'autre fichier qui aura un nom complété de l'extension `.png` contiendra une image au format PNG de cet arbre. + + +Voici ce qu'on obtient en reprenant les trois exemples précédents. + +* Exemple 1 + + $ ./main4.py 906028003040500001080900040600000070008206900030000005050003060100002080200870500 images/arbre_exple1 + Sudoku to solve + +-------+-------+-------+ + | 9 . 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | 5 . . | + +-------+-------+-------+ + Number of solution(s): 1 + -- + Solution 1 + +-------+-------+-------+ + | 9 1 6 | 4 2 8 | 7 5 3 | + | 3 4 2 | 5 6 7 | 8 9 1 | + | 7 8 5 | 9 3 1 | 2 4 6 | + +-------+-------+-------+ + | 6 2 9 | 3 4 5 | 1 7 8 | + | 5 7 8 | 2 1 6 | 9 3 4 | + | 4 3 1 | 7 8 9 | 6 2 5 | + +-------+-------+-------+ + | 8 5 7 | 1 9 3 | 4 6 2 | + | 1 9 4 | 6 5 2 | 3 8 7 | + | 2 6 3 | 8 7 4 | 5 1 9 | + +-------+-------+-------+ + -- + + Et voici l'image produite qui montre un arbre filiforme (signe que le sudoku est facile). La grille initiale est marquée en rouge en haut, et l'unique solution est marquée en vert en bas. Le premier nœud accessible depuis le nœud rouge de départ porte la mention `('7', 0, 6)`. Cela signifie que lors de la résolution, la première case remplie a été celle de coordonnée (0, 6) (première ligne, septième colonne) et qu'on y a placé le chiffre 7. + + ![arbre de résolution de l'exemple 1](images/arbre_exple1.png) + +* Exemple 2 + + $ ./main4.py 906028003040500001080900040600000070008206900030000005050003060100002080200870000 images/arbre_exple2 + Sudoku to solve + +-------+-------+-------+ + | 9 . 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | . . . | + +-------+-------+-------+ + Number of solution(s): 2 + -- + Solution 1 + +-------+-------+-------+ + | 9 1 6 | 4 2 8 | 7 5 3 | + | 3 4 2 | 5 6 7 | 8 9 1 | + | 7 8 5 | 9 3 1 | 2 4 6 | + +-------+-------+-------+ + | 6 2 9 | 3 4 5 | 1 7 8 | + | 5 7 8 | 2 1 6 | 9 3 4 | + | 4 3 1 | 7 8 9 | 6 2 5 | + +-------+-------+-------+ + | 8 5 7 | 1 9 3 | 4 6 2 | + | 1 9 4 | 6 5 2 | 3 8 7 | + | 2 6 3 | 8 7 4 | 5 1 9 | + +-------+-------+-------+ + -- + Solution 2 + +-------+-------+-------+ + | 9 1 6 | 4 2 8 | 7 5 3 | + | 3 4 2 | 5 6 7 | 8 9 1 | + | 7 8 5 | 9 3 1 | 2 4 6 | + +-------+-------+-------+ + | 6 2 9 | 3 5 4 | 1 7 8 | + | 5 7 8 | 2 1 6 | 9 3 4 | + | 4 3 1 | 7 8 9 | 6 2 5 | + +-------+-------+-------+ + | 8 5 7 | 1 9 3 | 4 6 2 | + | 1 9 3 | 6 4 2 | 5 8 7 | + | 2 6 4 | 8 7 5 | 3 1 9 | + +-------+-------+-------+ + + L'image produite montre que pendant un certain nombre d'étapes le parcours a été linéaire (aucun choix), puis une alternative s'est révélée chaque branche de cette alternative aboutissant à une solution, d'où les deux nœuds verts. + + ![arbre de résolution de l'exemple 2](images/arbre_exple2.png) + +* Exemple 3 + + $ ./main4.py 976028003040500001080900040600000070008206900030000005050003060100002080200870500 images/arbre_exple3 + Sudoku to solve + +-------+-------+-------+ + | 9 7 6 | . 2 8 | . . 3 | + | . 4 . | 5 . . | . . 1 | + | . 8 . | 9 . . | . 4 . | + +-------+-------+-------+ + | 6 . . | . . . | . 7 . | + | . . 8 | 2 . 6 | 9 . . | + | . 3 . | . . . | . . 5 | + +-------+-------+-------+ + | . 5 . | . . 3 | . 6 . | + | 1 . . | . . 2 | . 8 . | + | 2 . . | 8 7 . | 5 . . | + +-------+-------+-------+ + Number of solution(s): 0 + -- + + L'image produite montre un arbre ne comprenant qu'un seul nœud dont aucun vert. Cela provient du fait qu'une case impossible à remplir en respectant les contraintes a été découverte : la case (0, 6). + + ![arbre de résolution de l'exemple 3](images/arbre_exple3.png) + + +Avec la grille ci-dessous (grille de la ligne 43 du fichier `bdd/sudokus.bdd`) +-------+-------+-------+ | 2 . . | . 5 . | 8 4 . | @@ -41,11 +393,8 @@ Pour la grille ci-dessous (grille de la ligne 43 (en numérotant à partir de 0 | . . 8 | . 2 3 | . 5 . | | . 6 3 | . 1 . | . . 7 | +-------+-------+-------+ -après la commande - ./main4.py 200050840010790500000004000081000209300000005706000310000900000008023050063010007 images/sudokufiendish - -on obtient, outre la solution, deux fichiers `sudokufiendish.dot` et `sudokufiendish.png`décrivant l'arbre de recherche des solutions suivant +l'arbre de résolution révèle que cette grille n'a qu'une seule solution (un seul nœud vert), mais les nombreux branchements révèlent aussi de nombreuses impasses (fausse route) empruntées durant la recherche. ![Arbre de résolution d'un sudoku difficile](images/sudokufiendish.png) diff --git a/images/arbre_exple1.dot b/images/arbre_exple1.dot new file mode 100644 index 0000000..d770b88 --- /dev/null +++ b/images/arbre_exple1.dot @@ -0,0 +1,113 @@ +/* + Resolution tree for sudoku number +*/ +digraph T { + bgcolor="#FFFF00"; + node[style=filled]; + START[shape=hexagon, fillcolor="#FF0000"]; + "START706"[label="('7', 0, 6)"]; + "START" -> "START706"; + "START706101"[label="('1', 0, 1)"]; + "START706" -> "START706101"; + "START706101403"[label="('4', 0, 3)"]; + "START706101" -> "START706101403"; + "START706101403507"[label="('5', 0, 7)"]; + "START706101403" -> "START706101403507"; + "START706101403507715"[label="('7', 1, 5)"]; + "START706101403507" -> "START706101403507715"; + "START706101403507715310"[label="('3', 1, 0)"]; + "START706101403507715" -> "START706101403507715310"; + "START706101403507715310212"[label="('2', 1, 2)"]; + "START706101403507715310" -> "START706101403507715310212"; + "START706101403507715310212614"[label="('6', 1, 4)"]; + "START706101403507715310212" -> "START706101403507715310212614"; + "START706101403507715310212614816"[label="('8', 1, 6)"]; + "START706101403507715310212614" -> "START706101403507715310212614816"; + "START706101403507715310212614816917"[label="('9', 1, 7)"]; + "START706101403507715310212614816" -> "START706101403507715310212614816917"; + "START706101403507715310212614816917125"[label="('1', 2, 5)"]; + "START706101403507715310212614816917" -> "START706101403507715310212614816917125"; + "START706101403507715310212614816917125324"[label="('3', 2, 4)"]; + "START706101403507715310212614816917125" -> "START706101403507715310212614816917125324"; + "START706101403507715310212614816917125324741"[label="('7', 4, 1)"]; + "START706101403507715310212614816917125324" -> "START706101403507715310212614816917125324741"; + "START706101403507715310212614816917125324741448"[label="('4', 4, 8)"]; + "START706101403507715310212614816917125324741" -> "START706101403507715310212614816917125324741448"; + "START706101403507715310212614816917125324741448540"[label="('5', 4, 0)"]; + "START706101403507715310212614816917125324741448" -> "START706101403507715310212614816917125324741448540"; + "START706101403507715310212614816917125324741448540720"[label="('7', 2, 0)"]; + "START706101403507715310212614816917125324741448540" -> "START706101403507715310212614816917125324741448540720"; + "START706101403507715310212614816917125324741448540720522"[label="('5', 2, 2)"]; + "START706101403507715310212614816917125324741448540720" -> "START706101403507715310212614816917125324741448540720522"; + "START706101403507715310212614816917125324741448540720522144"[label="('1', 4, 4)"]; + "START706101403507715310212614816917125324741448540720522" -> "START706101403507715310212614816917125324741448540720522144"; + "START706101403507715310212614816917125324741448540720522144333"[label="('3', 3, 3)"]; + "START706101403507715310212614816917125324741448540720522144" -> "START706101403507715310212614816917125324741448540720522144333"; + "START706101403507715310212614816917125324741448540720522144333347"[label="('3', 4, 7)"]; + "START706101403507715310212614816917125324741448540720522144333" -> "START706101403507715310212614816917125324741448540720522144333347"; + "START706101403507715310212614816917125324741448540720522144333347450"[label="('4', 5, 0)"]; + "START706101403507715310212614816917125324741448540720522144333347" -> "START706101403507715310212614816917125324741448540720522144333347450"; + "START706101403507715310212614816917125324741448540720522144333347450753"[label="('7', 5, 3)"]; + "START706101403507715310212614816917125324741448540720522144333347450" -> "START706101403507715310212614816917125324741448540720522144333347450753"; + "START706101403507715310212614816917125324741448540720522144333347450753955"[label="('9', 5, 5)"]; + "START706101403507715310212614816917125324741448540720522144333347450753" -> "START706101403507715310212614816917125324741448540720522144333347450753955"; + "START706101403507715310212614816917125324741448540720522144333347450753955152"[label="('1', 5, 2)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955" -> "START706101403507715310212614816917125324741448540720522144333347450753955152"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932"[label="('9', 3, 2)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231"[label="('2', 3, 1)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136"[label="('1', 3, 6)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838"[label="('8', 3, 8)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854"[label="('8', 5, 4)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257"[label="('2', 5, 7)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656"[label="('6', 5, 6)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226"[label="('2', 2, 6)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628"[label="('6', 2, 8)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860"[label="('8', 6, 0)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163"[label="('1', 6, 3)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466"[label="('4', 6, 6)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762"[label="('7', 6, 2)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964"[label="('9', 6, 4)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268"[label="('2', 6, 8)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673"[label="('6', 7, 3)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971"[label="('9', 7, 1)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376"[label="('3', 7, 6)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472"[label="('4', 7, 2)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574"[label="('5', 7, 4)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434"[label="('4', 3, 4)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535"[label="('5', 3, 5)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778"[label="('7', 7, 8)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681"[label="('6', 8, 1)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382"[label="('3', 8, 2)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485"[label="('4', 8, 5)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485187"[label="('1', 8, 7)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485187"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485187988"[label="('9', 8, 8)"]; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485187" -> "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485187988"; + "START706101403507715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971376472574434535778681382485187988"[shape=hexagon, fillcolor="#00FF00"]; +} diff --git a/images/arbre_exple1.png b/images/arbre_exple1.png new file mode 100644 index 0000000..27f56cf Binary files /dev/null and b/images/arbre_exple1.png differ diff --git a/images/arbre_exple2.dot b/images/arbre_exple2.dot new file mode 100644 index 0000000..e78bf92 --- /dev/null +++ b/images/arbre_exple2.dot @@ -0,0 +1,132 @@ +/* + Resolution tree for sudoku number +*/ +digraph T { + bgcolor="#FFFF00"; + node[style=filled]; + START[shape=hexagon, fillcolor="#FF0000"]; + "START507"[label="('5', 0, 7)"]; + "START" -> "START507"; + "START507706"[label="('7', 0, 6)"]; + "START507" -> "START507706"; + "START507706101"[label="('1', 0, 1)"]; + "START507706" -> "START507706101"; + "START507706101403"[label="('4', 0, 3)"]; + "START507706101" -> "START507706101403"; + "START507706101403715"[label="('7', 1, 5)"]; + "START507706101403" -> "START507706101403715"; + "START507706101403715310"[label="('3', 1, 0)"]; + "START507706101403715" -> "START507706101403715310"; + "START507706101403715310212"[label="('2', 1, 2)"]; + "START507706101403715310" -> "START507706101403715310212"; + "START507706101403715310212614"[label="('6', 1, 4)"]; + "START507706101403715310212" -> "START507706101403715310212614"; + "START507706101403715310212614816"[label="('8', 1, 6)"]; + "START507706101403715310212614" -> "START507706101403715310212614816"; + "START507706101403715310212614816917"[label="('9', 1, 7)"]; + "START507706101403715310212614816" -> "START507706101403715310212614816917"; + "START507706101403715310212614816917125"[label="('1', 2, 5)"]; + "START507706101403715310212614816917" -> "START507706101403715310212614816917125"; + "START507706101403715310212614816917125324"[label="('3', 2, 4)"]; + "START507706101403715310212614816917125" -> "START507706101403715310212614816917125324"; + "START507706101403715310212614816917125324741"[label="('7', 4, 1)"]; + "START507706101403715310212614816917125324" -> "START507706101403715310212614816917125324741"; + "START507706101403715310212614816917125324741448"[label="('4', 4, 8)"]; + "START507706101403715310212614816917125324741" -> "START507706101403715310212614816917125324741448"; + "START507706101403715310212614816917125324741448540"[label="('5', 4, 0)"]; + "START507706101403715310212614816917125324741448" -> "START507706101403715310212614816917125324741448540"; + "START507706101403715310212614816917125324741448540720"[label="('7', 2, 0)"]; + "START507706101403715310212614816917125324741448540" -> "START507706101403715310212614816917125324741448540720"; + "START507706101403715310212614816917125324741448540720522"[label="('5', 2, 2)"]; + "START507706101403715310212614816917125324741448540720" -> "START507706101403715310212614816917125324741448540720522"; + "START507706101403715310212614816917125324741448540720522144"[label="('1', 4, 4)"]; + "START507706101403715310212614816917125324741448540720522" -> "START507706101403715310212614816917125324741448540720522144"; + "START507706101403715310212614816917125324741448540720522144333"[label="('3', 3, 3)"]; + "START507706101403715310212614816917125324741448540720522144" -> "START507706101403715310212614816917125324741448540720522144333"; + "START507706101403715310212614816917125324741448540720522144333347"[label="('3', 4, 7)"]; + "START507706101403715310212614816917125324741448540720522144333" -> "START507706101403715310212614816917125324741448540720522144333347"; + "START507706101403715310212614816917125324741448540720522144333347450"[label="('4', 5, 0)"]; + "START507706101403715310212614816917125324741448540720522144333347" -> "START507706101403715310212614816917125324741448540720522144333347450"; + "START507706101403715310212614816917125324741448540720522144333347450753"[label="('7', 5, 3)"]; + "START507706101403715310212614816917125324741448540720522144333347450" -> "START507706101403715310212614816917125324741448540720522144333347450753"; + "START507706101403715310212614816917125324741448540720522144333347450753955"[label="('9', 5, 5)"]; + "START507706101403715310212614816917125324741448540720522144333347450753" -> "START507706101403715310212614816917125324741448540720522144333347450753955"; + "START507706101403715310212614816917125324741448540720522144333347450753955152"[label="('1', 5, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955" -> "START507706101403715310212614816917125324741448540720522144333347450753955152"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932"[label="('9', 3, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231"[label="('2', 3, 1)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136"[label="('1', 3, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838"[label="('8', 3, 8)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854"[label="('8', 5, 4)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257"[label="('2', 5, 7)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656"[label="('6', 5, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226"[label="('2', 2, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628"[label="('6', 2, 8)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860"[label="('8', 6, 0)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163"[label="('1', 6, 3)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466"[label="('4', 6, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762"[label="('7', 6, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964"[label="('9', 6, 4)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268"[label="('2', 6, 8)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673"[label="('6', 7, 3)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971"[label="('9', 7, 1)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778"[label="('7', 7, 8)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681"[label="('6', 8, 1)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187"[label="('1', 8, 7)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988"[label="('9', 8, 8)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434"[label="('4', 3, 4)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535"[label="('5', 3, 5)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574"[label="('5', 7, 4)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376"[label="('3', 7, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472"[label="('4', 7, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382"[label="('3', 8, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382485"[label="('4', 8, 5)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382485"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382485586"[label="('5', 8, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382485" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382485586"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988434535574376472382485586"[shape=hexagon, fillcolor="#00FF00"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534"[label="('5', 3, 4)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435"[label="('4', 3, 5)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474"[label="('4', 7, 4)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372"[label="('3', 7, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576"[label="('5', 7, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482"[label="('4', 8, 2)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482585"[label="('5', 8, 5)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482585"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482585386"[label="('3', 8, 6)"]; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482585" -> "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482585386"; + "START507706101403715310212614816917125324741448540720522144333347450753955152932231136838854257656226628860163466762964268673971778681187988534435474372576482585386"[shape=hexagon, fillcolor="#00FF00"]; +} diff --git a/images/arbre_exple2.png b/images/arbre_exple2.png new file mode 100644 index 0000000..011023a Binary files /dev/null and b/images/arbre_exple2.png differ diff --git a/images/arbre_exple3.dot b/images/arbre_exple3.dot new file mode 100644 index 0000000..6cf231b --- /dev/null +++ b/images/arbre_exple3.dot @@ -0,0 +1,8 @@ +/* + Resolution tree for sudoku number +*/ +digraph T { + bgcolor="#FFFF00"; + node[style=filled]; + START[shape=hexagon, fillcolor="#FF0000"]; +} diff --git a/images/arbre_exple3.png b/images/arbre_exple3.png new file mode 100644 index 0000000..46d38fa Binary files /dev/null and b/images/arbre_exple3.png differ diff --git a/sudoku_mondrian.py b/sudoku_mondrian.py new file mode 100644 index 0000000..fc1ec8e --- /dev/null +++ b/sudoku_mondrian.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +""" +:mod:`sudoku_grid` module +:author: `Éric W` +:date: 2020, december + +Représentation de grilles de Sudoku sous la forme d'une image +« à la Mondrian » +""" + +from PIL import Image + +# Quelques constantes +# Epaisseur gros traits +EGT = 12 +# Epaisseur petits traits +EPT = 4 +# taille d'une case +LCASE = 40 +# dimension image +LGRILLE = 4*EGT + 6*EPT + 9*LCASE + +# Couleur traits +COUL_TRAITS = (0, 0, 0) +# Couleurs des cases +PALETTE = ((255, 255, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), + (255, 0, 255), (0, 255, 255), (255, 127, 127), (127, 255, 127), (127, 127, 255)) + +def colorie_case(img, coord, coul): + ''' + :param img: (Image) une image (une grille de sudoku) + :param coord: (tuple) couple de coordonnées d'une case + :param coul: (int) un entier compris entre 0 et 9 indice de la couleur dans la palette + :return: (NoneType) + :effet de bord: colorie la case de coordonnées coord de la grille img + avec la couleur coul + ''' + i, j = coord + f = lambda k : EGT + k//3 * (EGT + 2*EPT) + k%3 * EPT + k * LCASE + offsetx = f(i) + offsety = f(j) + for dx in range(LCASE): + for dy in range(LCASE): + img.putpixel((offsetx + dx, offsety + dy), PALETTE[coul]) + +def colorie_sudoku(grid): + ''' + :param grid: (SudokuGrid) la grille de Sudoku à représenter + :return: (Image) une image colorée représentant cette grille + ''' + img = Image.new('RGB', (LGRILLE, LGRILLE)) + # Les gros traits + # traits horizontaux + for i in range(4): + for k in range(EGT): + for x in range(LGRILLE): + img.putpixel((x, i*(EGT + 2*EPT + 3*LCASE) + k), COUL_TRAITS) + # traits verticaux + for j in range(4): + for k in range(EGT): + for y in range(LGRILLE): + img.putpixel((j*(EGT + 2*EPT + 3*LCASE) + k, y), COUL_TRAITS) + # Les petits traits + # horizontaux + for i in range(6): + for k in range(EPT): + for x in range(LGRILLE): + img.putpixel((x, (i//2 + 1)*EGT + i*EPT + (i + 1 + i//2)*LCASE), COUL_TRAITS) + # verticaux + for j in range(6): + for k in range(EPT): + for y in range(LGRILLE): + img.putpixel(((j//2 + 1)*EGT + j*EPT + (j + 1 + j//2)*LCASE, y), COUL_TRAITS) + # coloriage des cases + for x in range(9): + for y in range(9): + colorie_case(img, (x, y), int(grid[x, y])) + return img + + + +