petits changements
This commit is contained in:
@@ -137,9 +137,9 @@ class Grille implements ArrayAccess
|
|||||||
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
||||||
});
|
});
|
||||||
uksort($lettres_communes, function($a, $b) {
|
uksort($lettres_communes, function($a, $b) {
|
||||||
return $a == CASE_NOIRE;
|
return ($a == CASE_NOIRE)? 1 : -1;
|
||||||
});
|
});
|
||||||
$lettres_communes = array_slice($lettres_communes, 0, 3);
|
$lettres_communes = array_slice($lettres_communes, 0, 2);
|
||||||
|
|
||||||
foreach ($lettres_communes as $lettre => $_) {
|
foreach ($lettres_communes as $lettre => $_) {
|
||||||
$this->grille[$y][$x] = $lettre;
|
$this->grille[$y][$x] = $lettre;
|
||||||
|
|||||||
38
Trie.php
38
Trie.php
@@ -1,23 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
class Trie implements ArrayAccess, IteratorAggregate, Countable
|
||||||
|
{
|
||||||
public array $branches = [];
|
public array $branches = [];
|
||||||
private $nb_branches = 0;
|
private $nb_branches = 0;
|
||||||
|
|
||||||
public function arraySet($cles, $valeur) {
|
public function arraySet($cles, $valeur)
|
||||||
|
{
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$this->nb_branches++;
|
$this->nb_branches++;
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
$this->branches[$cle] = $valeur;
|
$this->branches[$cle] = $valeur;
|
||||||
} else {
|
} else {
|
||||||
if (!isset($this->branches[$cle])) $this->branches[$cle] = new Trie();
|
if (!isset($this->branches[$cle]))
|
||||||
|
$this->branches[$cle] = new Trie();
|
||||||
$this->branches[$cle]->arraySet($cles, $valeur);
|
$this->branches[$cle]->arraySet($cles, $valeur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrayExists($cles) {
|
public function arrayExists($cles)
|
||||||
|
{
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
@@ -27,7 +31,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function &arrayGet($cles) {
|
public function &arrayGet($cles)
|
||||||
|
{
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
@@ -37,7 +42,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrayUnset($cles) {
|
public function arrayUnset($cles)
|
||||||
|
{
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
@@ -53,28 +59,32 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ArrayAccess
|
// ArrayAccess
|
||||||
public function offsetSet($array, $valeur): void {
|
public function offsetSet($array, $valeur): void
|
||||||
|
{
|
||||||
if (is_string($array)) {
|
if (is_string($array)) {
|
||||||
$array = str_split($array);
|
$array = str_split($array);
|
||||||
}
|
}
|
||||||
$this->arraySet($array, $valeur);
|
$this->arraySet($array, $valeur);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists($array): bool {
|
public function offsetExists($array): bool
|
||||||
|
{
|
||||||
if (is_string($array)) {
|
if (is_string($array)) {
|
||||||
$array = str_split($array);
|
$array = str_split($array);
|
||||||
}
|
}
|
||||||
return $this->arrayExists($array);
|
return $this->arrayExists($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function &offsetGet($array): mixed {
|
public function &offsetGet($array): mixed
|
||||||
|
{
|
||||||
if (is_string($array)) {
|
if (is_string($array)) {
|
||||||
$array = str_split($array);
|
$array = str_split($array);
|
||||||
}
|
}
|
||||||
return $this->arrayGet($array);
|
return $this->arrayGet($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetUnset($array): void {
|
public function offsetUnset($array): void
|
||||||
|
{
|
||||||
if (is_string($array)) {
|
if (is_string($array)) {
|
||||||
$array = str_split($array);
|
$array = str_split($array);
|
||||||
}
|
}
|
||||||
@@ -82,10 +92,11 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IteratorAggregate
|
// IteratorAggregate
|
||||||
public function getIterator(): Traversable {
|
public function getIterator(): Traversable
|
||||||
|
{
|
||||||
foreach ($this->branches as $cle => $branche) {
|
foreach ($this->branches as $cle => $branche) {
|
||||||
if ($branche instanceof Trie) {
|
if ($branche instanceof Trie) {
|
||||||
foreach($branche->getIterator() as $sous_cles => $feuille) {
|
foreach ($branche->getIterator() as $sous_cles => $feuille) {
|
||||||
yield array_merge([$cle], $sous_cles) => $feuille;
|
yield array_merge([$cle], $sous_cles) => $feuille;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -95,7 +106,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Countable
|
// Countable
|
||||||
public function count(): int {
|
public function count(): int
|
||||||
|
{
|
||||||
return $this->nb_branches;
|
return $this->nb_branches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
dico.php
7
dico.php
@@ -6,7 +6,6 @@ include_once "Trie.php";
|
|||||||
const CASE_NOIRE = " ";
|
const CASE_NOIRE = " ";
|
||||||
const DEFINITION = 0;
|
const DEFINITION = 0;
|
||||||
const AUTEUR = 1;
|
const AUTEUR = 1;
|
||||||
const NB_MOTS = 2;
|
|
||||||
|
|
||||||
|
|
||||||
function dico($longueur_max) {
|
function dico($longueur_max) {
|
||||||
@@ -51,10 +50,10 @@ function dico($longueur_max) {
|
|||||||
return $dico;
|
return $dico;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mots_espaces($longueur_max) {
|
function mots_espaces($longueur_max, $longueur_min=1) {
|
||||||
$dico = dico($longueur_max);
|
$dico = dico($longueur_max);
|
||||||
for ($longueur = $longueur_max; $longueur >= 2; $longueur--) {
|
for ($longueur = $longueur_max; $longueur >= $longueur_min + 1; $longueur--) {
|
||||||
for ($position_espace = $longueur - 2; $position_espace >= 1; $position_espace--) {
|
for ($position_espace = $longueur - $longueur_min - 1; $position_espace >= $longueur_min; $position_espace--) {
|
||||||
$mots_suivants = $dico[$longueur - $position_espace - 1];
|
$mots_suivants = $dico[$longueur - $position_espace - 1];
|
||||||
foreach ($dico[$position_espace] as $premier_mot => $definition) {
|
foreach ($dico[$position_espace] as $premier_mot => $definition) {
|
||||||
$premier_mot[] = CASE_NOIRE;
|
$premier_mot[] = CASE_NOIRE;
|
||||||
|
|||||||
2
dico.tsv
2
dico.tsv
@@ -2691,7 +2691,7 @@ ORGANES Voix de presse Jacques Drillon
|
|||||||
ORIENT Est poétique Michel Laclos
|
ORIENT Est poétique Michel Laclos
|
||||||
ORIENTATION A sa table, on voit plus de reliefs que de plats Thierry Larsan
|
ORIENTATION A sa table, on voit plus de reliefs que de plats Thierry Larsan
|
||||||
ORIENTEES Ne sont pas nécessairement tournées vers l’est Georges Perec
|
ORIENTEES Ne sont pas nécessairement tournées vers l’est Georges Perec
|
||||||
ORIGAMI Ca ne se fait pas forcément avec le japon Thierry Larsan
|
ORIGAMI Ca ne se fait pas forcément avec le Japon Thierry Larsan
|
||||||
ORIN Il n'a pas bonne mine, mais il y tient Dédale
|
ORIN Il n'a pas bonne mine, mais il y tient Dédale
|
||||||
ORIN Filin qui retient une mine immergée
|
ORIN Filin qui retient une mine immergée
|
||||||
ORL Branche pour des rouges gorges Antoine Block
|
ORL Branche pour des rouges gorges Antoine Block
|
||||||
|
|||||||
|
Reference in New Issue
Block a user