All pastes #443659 Raw Edit

Shidame

public php v1 · immutable
·published 2007-04-16 22:23 UTC
rendered paste body
<?php$stars[1] = array(6,5);$stars[2] = array(4,8);$stars[3] = array(4);$stars[4] = array(2,3,6,7);// etc ...$start_sector = $from;$dest_sector = $to;$starAmount  = count($stars);if ($dest_sector < 1 || $dest_sector > $starAmount || $start_sector == $dest_sector) {	echo 'Autoway, destination invalide, essaye d\'autre coordonnées en paramètre GET<br />';	exit;}$ouptut_str   = '';for ($i = 1; $i < $starAmount; ++$i) {	$visit[$i] = 0;	$pred[$i]  = 0;	$dist[$i]  = 150;}$dist[$dest_sector] = 0;$queue = array($dest_sector);while ($search_sector = array_pop($queue)) {	$starLinks = $stars[$search_sector];	foreach ($starLinks as $vertex) {		if ($vertex == $start_sector) {			$path = array();			for ($linkback = $search_sector, $j = $dist[$search_sector] + 1; $linkback != $dest_sector && $j; --$j) {				$path[] = $linkback;				$linkback = $pred[$linkback];			}			$path[] = $dest_sector;			echo "<h1>" . count($path) . " bond(s) from #".$start_sector." to #".$dest_sector."</h1>";			echo "<p>Le chemin est : " . implode(' &raquo; ', $path) . "</p>";			exit;		}		if ($vertex > 0 && isset($visit[$vertex]) && $visit[$vertex] == 0) {			$visit[$vertex] = 1;			$dist[$vertex]  = $dist[$search_sector] + 1;			$pred[$vertex]  = $search_sector;			array_unshift($queue, $vertex);		}	}}echo 'Autoway, aucun chemin trouvé, essaye d\'autre coordonnées en paramètre GET<br />';?>