retour de la limite de mots
This commit is contained in:
parent
b85bf7eb99
commit
5997397908
@ -34,7 +34,7 @@ class Grille implements Iterator, ArrayAccess {
|
||||
$this->lettres_suivantes = [];
|
||||
foreach ($hauteur == $largeur ? [$hauteur] : [$hauteur, $largeur] as $longueur) {
|
||||
$this->lettres_suivantes[$longueur] = [];
|
||||
foreach (mots_espaces($longueur) as $mots) {
|
||||
foreach (mots_espaces($longueur, $hauteur == $largeur ? MAX_MOTS : MAX_MOTS/2) as $mots) {
|
||||
$mot = implode(" ", $mots);
|
||||
$ref = &$this->lettres_suivantes[$longueur];
|
||||
for ($i = 0; $i < $longueur; $i++) {
|
||||
|
8
dico.php
8
dico.php
@ -3,6 +3,7 @@
|
||||
|
||||
const MIN_LETTRES_MOT_1 = 2;
|
||||
const MIN_LETTRES_MOT_2 = 0;
|
||||
const MAX_MOTS = 1000000;
|
||||
|
||||
$dico = [[]];
|
||||
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||
@ -31,19 +32,22 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||
fclose($lecteur);
|
||||
}
|
||||
|
||||
function mots_espaces($longueur)
|
||||
function mots_espaces($longueur, $nb_mots_restants=MAX_MOTS)
|
||||
{
|
||||
global $dico;
|
||||
|
||||
foreach ($dico[$longueur] as $mot => $definition) {
|
||||
yield [$mot];
|
||||
if (--$nb_mots_restants <= 0) return;
|
||||
}
|
||||
for ($i = MIN_LETTRES_MOT_1; $longueur - $i - 1 >= MIN_LETTRES_MOT_2; $i++) {
|
||||
foreach ($dico[$i] as $mot => $definition) {
|
||||
foreach (mots_espaces($longueur - $i - 1) as $mots) {
|
||||
foreach (mots_espaces($longueur - $i - 1, $nb_mots_restants) as $mots) {
|
||||
if (!in_array($mot, $mots)) {
|
||||
yield [$mot, ...$mots];
|
||||
if (--$nb_mots_restants <= 0) return;
|
||||
yield [...$mots, $mot];
|
||||
if (--$nb_mots_restants <= 0) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user