Compare commits
No commits in common. "f1ceae33f4d14f866bf575e0e711269095bd5ac5" and "dbe228c6c20c927ed4eabc3cba48324b18a6e0a7" have entirely different histories.
f1ceae33f4
...
dbe228c6c2
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
__pycache__/
|
|
||||||
*.py
|
|
2
dico.csv
2
dico.csv
@ -1484,7 +1484,7 @@ NICE Beau, pour des anglais en promenade. Jean-Paul Vanden Branden
|
|||||||
NICE Agréable en angleterre comme en france. Robert Scipion
|
NICE Agréable en angleterre comme en france. Robert Scipion
|
||||||
NID Panier d’œufs. Marc Aussitot
|
NID Panier d’œufs. Marc Aussitot
|
||||||
NID Se fait petit à petit. Michel Laclos
|
NID Se fait petit à petit. Michel Laclos
|
||||||
NID Œuvre pie. Michel Laclos
|
NID OEuvre pie. Michel Laclos
|
||||||
NIE Parle pour ne rien dire. Dédale
|
NIE Parle pour ne rien dire. Dédale
|
||||||
NIE Infirme ou dément. Guy Hachette
|
NIE Infirme ou dément. Guy Hachette
|
||||||
NIET Tintin au pays des soviets. Marc Aussitot
|
NIET Tintin au pays des soviets. Marc Aussitot
|
||||||
|
Can't render this file because it contains an unexpected character in line 576 and column 23.
|
17
dico.php
17
dico.php
@ -12,20 +12,15 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
|||||||
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||||
if (substr($ligne[0], 0, 1) != "#" && count($ligne) >= 3) {
|
if (substr($ligne[0], 0, 1) != "#" && count($ligne) >= 3) {
|
||||||
[$mot, $definition, $auteur] = $ligne;
|
[$mot, $definition, $auteur] = $ligne;
|
||||||
$mot = strtoupper($mot);
|
|
||||||
if ($auteur) {
|
if ($auteur) {
|
||||||
$definition .= " <small><em>$auteur</em></small>";
|
$dico[strtoupper($mot)] = "$definition <small><em>$auteur</em></small>";
|
||||||
|
} else {
|
||||||
|
$dico[strtoupper($mot)] = $definition;
|
||||||
}
|
}
|
||||||
$nb_espaces = substr_count($mot, ' ');
|
$nb_espaces = substr_count($mot, ' ');
|
||||||
if ($nb_espaces > 0) {
|
if ($nb_espaces > 0) {
|
||||||
$definition .= " <small>(" . ($nb_espaces + 1) . " mots)</small>";
|
$dico[$mot] .= " <small>(" . ($nb_espaces + 1) . " mots)</small>";
|
||||||
}
|
}
|
||||||
if (strlen($definition)) {
|
|
||||||
$dico[$mot] = [$definition];
|
|
||||||
} else {
|
|
||||||
$dico[$mot] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($lecteur);
|
fclose($lecteur);
|
||||||
@ -67,9 +62,9 @@ function mots_espaces($longueur)
|
|||||||
foreach ($mots_de_n_lettres[$i] as $mot1) {
|
foreach ($mots_de_n_lettres[$i] as $mot1) {
|
||||||
foreach (mots_espaces($longueur - $i - 1) as $mot2) {
|
foreach (mots_espaces($longueur - $i - 1) as $mot2) {
|
||||||
if ($mot1 != $mot2) {
|
if ($mot1 != $mot2) {
|
||||||
$dico["$mot1 $mot2"] = array_merge($dico[$mot1], $dico[$mot2]);
|
$dico["$mot1 $mot2"] = $dico[$mot1] && $dico[$mot2] ? "<li>{$dico[$mot1]}</li><li>{$dico[$mot2]}</li>" : $dico[$mot1] . $dico[$mot2];
|
||||||
yield "$mot1 $mot2";
|
yield "$mot1 $mot2";
|
||||||
$dico["$mot2 $mot1"] = array_merge($dico[$mot2], $dico[$mot1]);
|
$dico["$mot2 $mot1"] = $dico[$mot2] && $dico[$mot1] ? "<li>{$dico[$mot2]}</li><li>{$dico[$mot1]}</li>" : $dico[$mot2] . $dico[$mot1];
|
||||||
yield "$mot2 $mot1";
|
yield "$mot2 $mot1";
|
||||||
$nb_mots += 2;
|
$nb_mots += 2;
|
||||||
if ($nb_mots > MAX_MOTS) {
|
if ($nb_mots > MAX_MOTS) {
|
||||||
|
28
index.php
28
index.php
@ -106,18 +106,7 @@ $grille = new Grille($hauteur, $largeur, $id);
|
|||||||
<h2>Horizontalement</h2>
|
<h2>Horizontalement</h2>
|
||||||
<ol>
|
<ol>
|
||||||
<?php for ($l = 0; $l < $hauteur; $l++): ?>
|
<?php for ($l = 0; $l < $hauteur; $l++): ?>
|
||||||
<li>
|
<li><ol><?= $dico[$grille->get_ligne($l, $largeur)] ?></ol></li>
|
||||||
<?php $definitions = $dico[$grille->get_ligne($l, $largeur)] ?>
|
|
||||||
<?php if (count($definitions) == 1): ?>
|
|
||||||
<?= $definitions[0] ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<ol>
|
|
||||||
<?php foreach ($dico[$grille->get_ligne($l, $largeur)] as $definition) : ?>
|
|
||||||
<li><?= $definition ?></li>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</ol>
|
|
||||||
<?php endif ?>
|
|
||||||
</li>
|
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
@ -125,23 +114,12 @@ $grille = new Grille($hauteur, $largeur, $id);
|
|||||||
<h2>Verticalement</h2>
|
<h2>Verticalement</h2>
|
||||||
<ol type="A">
|
<ol type="A">
|
||||||
<?php for ($c = 0; $c < $largeur; $c++): ?>
|
<?php for ($c = 0; $c < $largeur; $c++): ?>
|
||||||
<li>
|
<li><ol><?= $dico[$grille->get_colonne($c, $hauteur)] ?></ol></li>
|
||||||
<?php $definitions = $dico[$grille->get_colonne($c, $hauteur)] ?>
|
|
||||||
<?php if (count($definitions) == 1): ?>
|
|
||||||
<?= $definitions[0] ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<ol>
|
|
||||||
<?php foreach ($dico[$grille->get_colonne($c, $hauteur)] as $definition) : ?>
|
|
||||||
<li><?= $definition ?></li>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</ol>
|
|
||||||
<?php endif ?>
|
|
||||||
</li>
|
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" id="lignes" <?php if (isset($_GET["lignes"])): ?>name="lignes" <?php endif ?>value="<?= $hauteur ?>" />
|
<input type="hidden" id="lignes" <?php if (isset($_GET["lignes"])): ?>name="lignes" <?php endif ?>value="<?= $hauteur ?>" />
|
||||||
<input type="hidden" id="colonnes" <?php if (isset($_GET["colonnes"])): ?>name="colonnes" <?php endif ?>value="<?= $largeur ?>" />
|
<input type="hidden" id="colonnes" <?php if (isset($_GET["colonnes"])): ?>name="colonnes" <?php endif ?>value="<?= $largeur ?>" />
|
||||||
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
|
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
|
||||||
|
19
style.css
19
style.css
@ -1,7 +1,6 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background-color: white;
|
|
||||||
font-family: Times, 'Times New Roman', Georgia, serif;
|
font-family: Times, 'Times New Roman', Georgia, serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ table.grille {
|
|||||||
height: 2rem;
|
height: 2rem;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
background-color: white;
|
font-family: 'Comic Sans MS', 'Comic Sans', cursive, sans;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grille tr:nth-of-type(2) td {
|
.grille tr:nth-of-type(2) td {
|
||||||
@ -80,8 +79,6 @@ table.grille {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
font-family: 'Comic Sans MS', 'Comic Sans', sans;
|
|
||||||
color: darkblue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.grille input[disabled] {
|
.grille input[disabled] {
|
||||||
@ -107,11 +104,7 @@ table.grille {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.definitions li ol {
|
.definitions li ol {
|
||||||
padding-left: 0em;
|
padding-left: 0.8em;
|
||||||
}
|
|
||||||
|
|
||||||
.definitions li li {
|
|
||||||
margin-left: 0.8em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.definitions li li::marker {
|
.definitions li li::marker {
|
||||||
@ -181,11 +174,3 @@ button[type="submit"]:active {
|
|||||||
-ms-text-size-adjust: 100%;
|
-ms-text-size-adjust: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
body,
|
|
||||||
button {
|
|
||||||
background-color: #02081a;
|
|
||||||
color: #c6c6c6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
144
test.py
Normal file
144
test.py
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
import csv
|
||||||
|
from re import compile, match
|
||||||
|
from random import choice, sample, randrange
|
||||||
|
from collections import defaultdict
|
||||||
|
from math import ceil
|
||||||
|
from itertools import product, chain
|
||||||
|
|
||||||
|
|
||||||
|
dico = defaultdict(list)
|
||||||
|
with open("dico.csv", "r", encoding="utf-8") as fichier:
|
||||||
|
for mot, definition in csv.reader(fichier, delimiter="\t"):
|
||||||
|
if not mot.startswith("#"):
|
||||||
|
dico[mot].append(definition)
|
||||||
|
|
||||||
|
mots_de_n_lettres = defaultdict(set)
|
||||||
|
for mot in dico:
|
||||||
|
mots_de_n_lettres[len(mot)].add(mot)
|
||||||
|
|
||||||
|
|
||||||
|
def mots_espaces(n):
|
||||||
|
for mot in mots_de_n_lettres[n]:
|
||||||
|
yield mot
|
||||||
|
# for mot in mots_de_n_lettres[n-1]:
|
||||||
|
# yield f"{mot} "
|
||||||
|
# yield f" {mot}"
|
||||||
|
for i in range(1, ceil(n / 2)):
|
||||||
|
for mot1, mot2 in product(mots_de_n_lettres[i], mots_espaces(n - i - 1)):
|
||||||
|
yield f"{mot1} {mot2}"
|
||||||
|
yield f"{mot2} {mot1}"
|
||||||
|
# for mot1, mot2 in product(mots_de_n_lettres[i], mots_espaces(n - i - 2)):
|
||||||
|
# yield f" {mot1} {mot2}"
|
||||||
|
# yield f"{mot2} {mot1} "
|
||||||
|
# for mot1, mot2 in product(mots_de_n_lettres[i-1], mots_espaces(n - i - 1)):
|
||||||
|
# yield f" {mot1} {mot2}"
|
||||||
|
# yield f"{mot2} {mot1} "
|
||||||
|
|
||||||
|
|
||||||
|
class Ligne:
|
||||||
|
def __init__(self, grille):
|
||||||
|
self.grille = grille
|
||||||
|
|
||||||
|
def __getitem__(self, n):
|
||||||
|
return "".join(self.grille[n])
|
||||||
|
|
||||||
|
def __setitem__(self, n, mot):
|
||||||
|
self.grille[n] = list(mot)
|
||||||
|
|
||||||
|
|
||||||
|
class Colonne:
|
||||||
|
def __init__(self, grille):
|
||||||
|
self.grille = grille
|
||||||
|
|
||||||
|
def __getitem__(self, n):
|
||||||
|
return "".join(ligne[n] for ligne in self.grille)
|
||||||
|
|
||||||
|
def __setitem__(self, n, mot):
|
||||||
|
for i, char in enumerate(mot):
|
||||||
|
self.grille[i][n] = char
|
||||||
|
|
||||||
|
|
||||||
|
class Grille:
|
||||||
|
def __init__(self, hauteur, largeur):
|
||||||
|
self.hauteur = hauteur
|
||||||
|
self.largeur = largeur
|
||||||
|
self.grille = [["." for _ in range(largeur)] for _ in range(hauteur)]
|
||||||
|
self.ligne = Ligne(self.grille)
|
||||||
|
self.colonne = Colonne(self.grille)
|
||||||
|
|
||||||
|
self.mots_commencant_par = defaultdict(lambda: defaultdict(list))
|
||||||
|
for dimension in (hauteur,) if hauteur == largeur else (hauteur, largeur):
|
||||||
|
for mot in mots_espaces(dimension):
|
||||||
|
for i in range(dimension+1):
|
||||||
|
self.mots_commencant_par[dimension][mot[:i]].append(mot)
|
||||||
|
|
||||||
|
self.grilles = self.genere_grilles()
|
||||||
|
next(self.grilles)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
return next(self.grilles)
|
||||||
|
|
||||||
|
def genere_grilles(self):
|
||||||
|
print(f"Grille({self.hauteur}, {self.largeur})")
|
||||||
|
yield from self.trouve_une_ligne(0)
|
||||||
|
|
||||||
|
def trouve_une_ligne(self, l):
|
||||||
|
for mot in self.mots_commencant_par[self.largeur][self.ligne[l][:l]]:
|
||||||
|
self.ligne[l] = mot
|
||||||
|
if all(
|
||||||
|
self.colonne[c][:l+1] in self.mots_commencant_par[self.hauteur]
|
||||||
|
for c in range(l, self.largeur)
|
||||||
|
):
|
||||||
|
if l < self.largeur:
|
||||||
|
yield from self.trouve_une_colonne(l)
|
||||||
|
elif l + 1 < self.hauteur:
|
||||||
|
yield from self.trouve_une_ligne(l + 1)
|
||||||
|
else:
|
||||||
|
yield self
|
||||||
|
|
||||||
|
def trouve_une_colonne(self, c):
|
||||||
|
for mot in self.mots_commencant_par[self.hauteur][self.colonne[c][:c+1]]:
|
||||||
|
self.colonne[c] = mot
|
||||||
|
if all(
|
||||||
|
self.ligne[l][:c+1] in self.mots_commencant_par[self.largeur]
|
||||||
|
for l in range(c, self.largeur)
|
||||||
|
):
|
||||||
|
if c + 1 < self.hauteur:
|
||||||
|
yield from self.trouve_une_ligne(c + 1)
|
||||||
|
elif c + 1 < self.largeur:
|
||||||
|
yield from self.trouve_une_colonne(c + 1)
|
||||||
|
else:
|
||||||
|
yield self
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return (
|
||||||
|
" "
|
||||||
|
+ " ".join(chr(65 + i) for i in range(self.largeur))
|
||||||
|
+ "\n"
|
||||||
|
+ "\n".join(
|
||||||
|
f"{i + 1:2} " + " ".join(ligne) for i, ligne in enumerate(self.grille)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.__str__()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import time
|
||||||
|
|
||||||
|
class Timer:
|
||||||
|
def __enter__(self):
|
||||||
|
self.start = time.time()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *exc_info):
|
||||||
|
end = time.time()
|
||||||
|
print(f"Execution time: {end - self.start:.2f} seconds")
|
||||||
|
|
||||||
|
for n in range(2, 14):
|
||||||
|
with Timer():
|
||||||
|
print(Grille(n, n))
|
Loading…
x
Reference in New Issue
Block a user