Last active
December 16, 2015 20:08
-
-
Save juanmboehme/5489792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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