limite nombre de mots

This commit is contained in:
2025-05-01 17:40:35 +02:00
parent 6db7e7ab63
commit 4874bc0d78
2 changed files with 7 additions and 4 deletions

View File

@ -2,7 +2,8 @@
const MIN_LETTRES_MOT_1 = 2;
const MIN_LETTRES_MOT_2 = 1;
const MIN_LETTRES_MOT_2 = 0;
const MAX_MOTS = 1000000;
$dico = [];
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
@ -27,20 +28,22 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
fclose($lecteur);
}
function mots_espaces($longueur)
function mots_espaces($longueur, $nb_mots=0)
{
global $dico;
$nb_mots = 0;
foreach ($dico[$longueur] as $mot => $definition) {
yield $mot;
if (++$nb_mots >= MAX_MOTS) return;
}
for ($i = MIN_LETTRES_MOT_1; $longueur - $i - 1 >= MIN_LETTRES_MOT_2; $i++) {
foreach ($dico[$i] as $mot1 => $definition) {
foreach (mots_espaces($longueur - $i - 1) as $mot2) {
if ($mot1 != $mot2) {
yield "$mot1 $mot2";
if (++$nb_mots >= MAX_MOTS) return;
yield "$mot2 $mot1";
if (++$nb_mots >= MAX_MOTS) return;
}
}
}