* @copyright 2025 Bartolomé Sintes Marco
* @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later
* @version 2025-02-08
* @link https://www.mclibre.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
function cabecera($texto)
{
print "\n";
print "\n";
print "
Escribe los valores numéricos (puedes escribir entre $numeroValoresMinimo y $numeroValoresMaximo valores):
\n";
print "\n";
}
print " \n";
print "\n";
// Si los valores son correctos se convierten a cadena
} else {
cabecera("Resultado válido");
print "
Los datos introducidos son correctos.
\n";
print "\n";
print "
Datos introducidos (* si falta un dato): ";
for ($i = 1; $i <= $numeroValores; $i++) {
if ($valores[$i] == "") {
print "* ";
} else {
print "$valores[$i] ";
}
}
print "
\n";
print "\n";
$simpleEncoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// Empiezo buscando un valor cualquiera en la lista de valores
$minimo = $maximo = 0;
$patronValores = "/^[+-]?[0-9]{1,6}$/"; // Este patrón NO admite la cadena vacía
foreach ($valores as $valor) {
if (preg_match($patronValores, $valor)) {
$minimo = $maximo = $valor;
}
}
// Después busco el máximo y el mínimo (las funciones min y max
// no sirven porque puede haber valores vacíos
foreach ($valores as $valor) {
if ($valor != "") {
if ($valor > $maximo) {
$maximo = $valor;
}
if ($valor < $minimo) {
$minimo = $valor;
}
}
}
// Por último se convierten a la cadena
$cadena = "";
if ($maximo == $minimo) {
foreach ($valores as $valor) {
if ($valor == "") {
$cadena .= "_";
} else {
$cadena .= "f";
}
}
} else {
foreach ($valores as $valor) {
if ($valor == "") {
$cadena .= "_";
} else {
$letra = round(($valor - $minimo) / ($maximo - $minimo) * 61);
$cadena .= $simpleEncoding[$letra];
}
}
}
print "
La cadena correspondiente a estos valores es: $cadena