3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo "<h1>Hello, PHP!</h1>"; $file = fopen("input.txt","r"); $list = new SplDoublyLinkedList(); //$list = new LinkList(); while(! feof($file)) { //print_r(fgetcsv($file)); $list->push(fgets($file)); //print_r(fgets($file)); } fclose($file); $list->rewind(); $currCityP = str_getcsv($list->current()); $string=implode(",",$currCityP); //echo "Init CurrCityP".$string."\r\n<br>"; $nextCityP = str_getcsv($list->current()); $string=implode(",",$nextCityP); //echo "Init nextCityP".$string."\r\n<br>"; //echo "Total num of cities is: ".$list->count()."\r\n<br>"; for ($x=1; $x<=$list->count(); $x++) { $currCityP = $nextCityP; $y=1; $min=10000; for ($list->rewind(); $list->valid(); $list->next()) { $tmpCityP = str_getcsv($list->current()); if ($y == $x+1) { $nextCityP = $tmpCityP; //echo "x & y are: ".$x.", ".$y."\r\n<br>"; } $y++; $dist = sqrt(pow(($tmpCityP[0]-$currCityP[0]),2)+pow(($tmpCityP[1]-$currCityP[1]),2)); if ($min > $dist && $dist != 0) { $min = $dist; } //echo "Distane".$dist."\r\n"; //echo "next\r\n"; } $string=implode(",",$currCityP); //echo "CurrCityP is: ".$string."\r\n<br>"; $string=implode(",",$nextCityP); //echo "NextCityP is: ".$string."\r\n<br>"; echo $min."\r\n<br>"; }