Skip to content

Instantly share code, notes, and snippets.

@juanmboehme
Last active December 16, 2015 20:08
Show Gist options
  • Save juanmboehme/5489792 to your computer and use it in GitHub Desktop.
Save juanmboehme/5489792 to your computer and use it in GitHub Desktop.
<?php
$time=time();
class Palindromo{
public static function empezar(){
$archivo = fopen("file2.txt","r");
$primero=array();
$segundo=array();
$final=array();
$total=0;
while(!feof($archivo)){
$registro = fgets($archivo);
$rango = explode(" ", $registro);
array_push($final, $rango);
array_push($primero, trim($rango[0]));
array_push($segundo, trim($rango[1]));
}
sort($primero);
sort($segundo);
$Primer_numero=(int)$primero[0];
$Segundo_numero=(int)$segundo[count($segundo)-1];
for($x=$Primer_numero;$x<$Segundo_numero;$x++)
{
if($x==strrev($x))
{
$cantArray=count($final);
for($z=0;$z<$cantArray;$z++)
{
/*Validate When Range is from x to x like 2002 2002*/
if($final[$z][1]>=$x)
{
if($final[$z][0]<=$x)
{
$total++;
}
}
}
}
}
echo $total.'<br>';
}
}
Palindromo::empezar();
echo time()-$time;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment