fusion de dico et mot_de_n_lettres, favicon en svg

This commit is contained in:
2025-05-01 17:11:32 +02:00
parent 9546ac4d97
commit 6db7e7ab63
5 changed files with 153 additions and 110 deletions

View File

@ -11,51 +11,35 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
if (substr($ligne[0], 0, 1) != "#" && count($ligne) >= 3) {
[$mot, $definition, $auteur] = $ligne;
$mot = strtoupper($mot);
$longueur = strlen($mot);
if ($auteur) {
$definition .= " <small><em>$auteur</em></small>";
}
$nb_espaces = substr_count($mot, ' ');
if ($nb_espaces > 0) {
$definition .= " <small>(" . ($nb_espaces + 1) . " mots)</small>";
if (!isset($dico[$longueur])) {
$dico[$longueur] = [];
}
if (strlen($definition)) {
$dico[$mot] = [$definition];
} else {
$dico[$mot] = [];
if (!isset($dico[$longueur][$mot])) {
$dico[$longueur][$mot] = [];
}
$dico[$longueur][$mot][] = $definition;
}
}
fclose($lecteur);
}
$mots_de_n_lettres = [];
foreach ($dico as $mot => $definition) {
$n = strlen($mot);
if (!isset($mots_de_n_lettres[$n])) {
$mots_de_n_lettres[$n] = [];
}
$mots_de_n_lettres[$n][] = $mot;
if (!empty($definitions)) {
$dico[$mot] = [$definitions[array_rand($definitions)]];
}
}
function mots_espaces($longueur)
{
global $mots_de_n_lettres;
global $dico;
$nb_mots = 0;
foreach ($mots_de_n_lettres[$longueur] as $mot) {
foreach ($dico[$longueur] as $mot => $definition) {
yield $mot;
}
for ($i = MIN_LETTRES_MOT_1; $longueur - $i - 1 >= MIN_LETTRES_MOT_2; $i++) {
foreach ($mots_de_n_lettres[$i] as $mot1) {
foreach ($dico[$i] as $mot1 => $definition) {
foreach (mots_espaces($longueur - $i - 1) as $mot2) {
if ($mot1 != $mot2) {
$dico["$mot1 $mot2"] = array_merge($dico[$mot1], $dico[$mot2]);
yield "$mot1 $mot2";
$dico["$mot2 $mot1"] = array_merge($dico[$mot2], $dico[$mot1]);
yield "$mot2 $mot1";
}
}