Compare commits
3 Commits
dbe228c6c2
...
f1ceae33f4
Author | SHA1 | Date | |
---|---|---|---|
f1ceae33f4 | |||
584f1a81a0 | |||
bcfe6da555 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
__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 OEuvre pie. Michel Laclos
|
NID Œuvre 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,15 +12,20 @@ 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) {
|
||||||
$dico[strtoupper($mot)] = "$definition <small><em>$auteur</em></small>";
|
$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) {
|
||||||
$dico[$mot] .= " <small>(" . ($nb_espaces + 1) . " mots)</small>";
|
$definition .= " <small>(" . ($nb_espaces + 1) . " mots)</small>";
|
||||||
}
|
}
|
||||||
|
if (strlen($definition)) {
|
||||||
|
$dico[$mot] = [$definition];
|
||||||
|
} else {
|
||||||
|
$dico[$mot] = [];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($lecteur);
|
fclose($lecteur);
|
||||||
@ -62,9 +67,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"] = $dico[$mot1] && $dico[$mot2] ? "<li>{$dico[$mot1]}</li><li>{$dico[$mot2]}</li>" : $dico[$mot1] . $dico[$mot2];
|
$dico["$mot1 $mot2"] = array_merge($dico[$mot1], $dico[$mot2]);
|
||||||
yield "$mot1 $mot2";
|
yield "$mot1 $mot2";
|
||||||
$dico["$mot2 $mot1"] = $dico[$mot2] && $dico[$mot1] ? "<li>{$dico[$mot2]}</li><li>{$dico[$mot1]}</li>" : $dico[$mot2] . $dico[$mot1];
|
$dico["$mot2 $mot1"] = array_merge($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) {
|
||||||
|
26
index.php
26
index.php
@ -106,7 +106,18 @@ $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><ol><?= $dico[$grille->get_ligne($l, $largeur)] ?></ol></li>
|
<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>
|
||||||
@ -114,7 +125,18 @@ $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><ol><?= $dico[$grille->get_colonne($c, $hauteur)] ?></ol></li>
|
<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>
|
||||||
|
19
style.css
19
style.css
@ -1,6 +1,7 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ table.grille {
|
|||||||
height: 2rem;
|
height: 2rem;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
font-family: 'Comic Sans MS', 'Comic Sans', cursive, sans;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grille tr:nth-of-type(2) td {
|
.grille tr:nth-of-type(2) td {
|
||||||
@ -79,6 +80,8 @@ 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] {
|
||||||
@ -104,7 +107,11 @@ table.grille {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.definitions li ol {
|
.definitions li ol {
|
||||||
padding-left: 0.8em;
|
padding-left: 0em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.definitions li li {
|
||||||
|
margin-left: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.definitions li li::marker {
|
.definitions li li::marker {
|
||||||
@ -174,3 +181,11 @@ 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
144
test.py
@ -1,144 +0,0 @@
|
|||||||
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