$auteur"; break; } $mot = strtoupper($mot); $longueur = strlen($mot); if (!isset($dico[$longueur])) $dico[$longueur] = []; if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = []; if (strlen($definition)) $dico[$longueur][$mot][] = $definition; } fclose($lecteur); } function mots_espaces($longueur) { global $dico; foreach ($dico[$longueur] as $mot => $definition) { yield [$mot]; } for ($i = MIN_LETTRES_MOT_1; ($j = $longueur - $i - 1) >= MIN_LETTRES_MOT_2; $i++) { foreach ($dico[$i] as $mot => $definition) { foreach (mots_espaces($j) as $mots) { if (!in_array($mot, $mots)) { yield [$mot, ...$mots]; } } } } } function permutations(array $elements) { if (count($elements) <= 1) { yield $elements; } else { foreach (permutations(array_slice($elements, 1)) as $permutation) { foreach (range(0, count($elements) - 1) as $i) { yield [...array_slice($permutation, 0, $i), $elements[0], ...array_slice($permutation, $i)]; } } } } function mots_permutes($longueur) { foreach (mots_espaces($longueur) as $mots) { yield from permutations($mots); } }