on commence par le début

This commit is contained in:
2025-04-24 04:10:25 +02:00
parent cb71fbe68a
commit b70b8cdc56
7 changed files with 630 additions and 242 deletions

44
dico.php Normal file
View File

@ -0,0 +1,44 @@
<?php
$dico = [];
if (($handle = fopen("dico.csv", "r")) !== FALSE) {
$header = fgetcsv($handle, 0, "\t");
while (($ligne = fgetcsv($handle, 0, "\t")) !== FALSE) {
if (count($ligne) >= 2) {
$mot = $ligne[0];
$definition = $ligne[1];
$dico[$mot] = $definition;
}
}
fclose($handle);
}
$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;
}
foreach ($mots_de_n_lettres as $n => $mots) {
shuffle($mots_de_n_lettres[$n]);
}
function mots_espaces($max, $min=0) {
global $mots_de_n_lettres;
foreach($mots_de_n_lettres[$max] as $mot) {
yield $mot;
}
for ($i = ceil($max / 2); $max - $i -1 >= $min; $i++) {
foreach ($mots_de_n_lettres[$i] as $mot1) {
foreach (mots_espaces($max - $i -1, $min) as $mot2) {
if ($mot1 != $mot2) {
yield "$mot1 $mot2";
yield "$mot2 $mot1";
}
}
}
}
}