From 168fc5f7a2e4e686f6f2672c691bf2a0d1124468 Mon Sep 17 00:00:00 2001 From: adrien Date: Sat, 3 May 2025 02:36:46 +0200 Subject: [PATCH] moins de comparaisons --- Grille.php | 27 +++++++++++++-------------- index.php | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Grille.php b/Grille.php index 167c164..919711b 100644 --- a/Grille.php +++ b/Grille.php @@ -99,22 +99,21 @@ class Grille implements Iterator, ArrayAccess { $this->grille[$y][$x] = $lettre; $this->lignes[$y] = []; - $mots = []; - if ($x == $this->largeur - 1) $mots = explode(" ", $this->get_ligne($y, $this->largeur)); - else if ($lettre == " ") $mots = explode(" ", $this->get_ligne($y, $x)); - foreach ($mots as $rang => $mot) { - if (strlen($mot) <= 1) continue; - if (in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2; - $this->lignes[$y][$rang] = $mot; + if ($x == $this->largeur - 1) $this->lignes[$y] = explode(" ", $this->get_ligne($y, $this->largeur)); + else if ($lettre == " ") $this->lignes[$y] = explode(" ", $this->get_ligne($y, $x)); + if (count($this->lignes[$y])) { + $mot = array_pop($this->lignes[$y]); + if (strlen($mot) >= 1 && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue; + $this->lignes[$y][] = $mot; } + $this->colonnes[$x] = []; - $mots = []; - if ($y == $this->hauteur - 1) $mots = explode(" ", $this->get_colonne($x, $this->hauteur)); - else if ($lettre == " ") $mots = explode(" ", $this->get_colonne($x, $y)); - foreach ($mots as $rang => $mot) { - if (strlen($mot) == 1) continue; - if (in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2; - $this->colonnes[$x][$rang] = $mot; + if ($y == $this->hauteur - 1) $this->colonnes[$x] = explode(" ", $this->get_colonne($x, $this->hauteur)); + else if ($lettre == " ") $this->colonnes[$x] = explode(" ", $this->get_colonne($x, $y)); + if (count($this->colonnes[$x])) { + $mot = array_pop($this->colonnes[$x]); + if (strlen($mot) >= 1 && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue; + $this->colonnes[$x][] = $mot; } if ($i < $this->nb_positions) { diff --git a/index.php b/index.php index 8217378..cfc9b20 100644 --- a/index.php +++ b/index.php @@ -65,7 +65,7 @@ if ($grille->valid()) { - MOTS■CROISÉS + MOTS CROISÉS