Skip to content

Instantly share code, notes, and snippets.

@reneolivo
Last active December 16, 2015 12:49
Show Gist options
  • Save reneolivo/5437727 to your computer and use it in GitHub Desktop.
Save reneolivo/5437727 to your computer and use it in GitHub Desktop.
<?php
function esPalindromo($cadena) {
return $cadena == strrev($cadena);
}
$contador = 0;
$tiempoInicio = microtime(TRUE);
$urlArchivo = 'seed.txt';
$puntero = fopen($urlArchivo, 'r');
while(!feof($puntero)):
$linea = fgets($puntero);
$rango = explode(' ', $linea);
$rango[0] = (int) $rango[0];
$rango[1] = (int) $rango[1];
for($i = $rango[0]; $i <= $rango[1]; $i++)
if (esPalindromo($i))
$contador++;
endwhile;
$tiempoFin = microtime(TRUE);
$tiempoTotal = $tiempoFin - $tiempoInicio;
echo "<pre>
Encontradas : {$contador}
Inicio : {$tiempoInicio}
Fin : {$tiempoFin}
Tiempo Total : {$tiempoTotal}
</pre>";
?>
@hminaya
Copy link

hminaya commented Apr 22, 2013

revisalo, me dio un numero menos.

@reneolivo
Copy link
Author

No te dió 18,178?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment