liste unique de définition

This commit is contained in:
Adrien MALINGREY 2025-04-28 17:17:58 +02:00
parent bcfe6da555
commit 584f1a81a0
2 changed files with 36 additions and 9 deletions

View File

@ -12,15 +12,20 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
if (substr($ligne[0], 0, 1) != "#" && count($ligne) >= 3) {
[$mot, $definition, $auteur] = $ligne;
$mot = strtoupper($mot);
if ($auteur) {
$dico[strtoupper($mot)] = "$definition <small><em>$auteur</em></small>";
} else {
$dico[strtoupper($mot)] = $definition;
$definition .= " <small><em>$auteur</em></small>";
}
$nb_espaces = substr_count($mot, ' ');
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);
@ -62,9 +67,9 @@ function mots_espaces($longueur)
foreach ($mots_de_n_lettres[$i] as $mot1) {
foreach (mots_espaces($longueur - $i - 1) as $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";
$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";
$nb_mots += 2;
if ($nb_mots > MAX_MOTS) {

View File

@ -106,7 +106,18 @@ $grille = new Grille($hauteur, $largeur, $id);
<h2>Horizontalement</h2>
<ol>
<?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; ?>
</ol>
</div>
@ -114,12 +125,23 @@ $grille = new Grille($hauteur, $largeur, $id);
<h2>Verticalement</h2>
<ol type="A">
<?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; ?>
</ol>
</div>
</div>
<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="solution_hashee" value="<?= $grille->hash() ?>" />