<?php
SUBWAY => 'едешь на метро' ,
FOOT => 'идешь пешком' ,
BUS => 'едешь на автобусе'
) ;
$startPoint = 'pet' ; // Петроградская
$endPoint = 'nov' ; // Новая Голландия
$pathDone = [ ] ;
$time = 0 ;
$tempTime = 0 ;
'pet' => 'ст. м. Петроградская' ,
'chk' => 'ст. м. Чкаловская' ,
'gor' => 'ст. м. Горьковская' ,
'spo' => 'ст. м. Спортивная' ,
'vas' => 'ст. м. Василеостровская' ,
'kre' => 'Петропавловская крепость' ,
'let' => 'Летний сад' ,
'dvo' => 'Дворцовая площадь' ,
'isa' => 'Исакиевский собор' ,
'nov' => 'Новая Голландия' ,
'ras' => 'Дом Раскольникова' ,
'gos' => 'Гостиный Двор' ,
'sen' => 'Сенная Площадь' ,
'vla' => 'ст. м. Владимирская' ,
'vit' => 'Витебский вокзал' ,
'teh' => 'Технологический Институт'
) ;
'chk' => canGet( 10 , BUS) ,
'gor' => canGet( 3 , SUBWAY)
) ,
'pet' => canGet( 10 , BUS) ,
'spo' => canGet( 3 , SUBWAY)
) ,
'pet' => canGet( 3 , BUS) ,
'kre' => canGet( 5 , FOOT) ,
'gos' => canGet( 6 , SUBWAY)
) ,
'chk' => canGet( 3 , SUBWAY) ,
'vas' => canGet( 10 , BUS) ,
'sen' => canGet( 7 , SUBWAY)
) ,
'spo' => canGet( 10 , BUS) ,
'gos' => canGet( 7 , SUBWAY) ,
'nov' => canGet( 11 , FOOT)
) ,
'gor' => canGet( 5 , FOOT)
) ,
'dvo' => canGet( 6 , FOOT) ,
'gos' => canGet( 7 , FOOT)
) ,
'isa' => canGet( 6 , FOOT) ,
'gos' => canGet( 6 , FOOT) ,
'let' => canGet( 6 , FOOT)
) ,
'dvo' => canGet( 6 , FOOT) ,
'nov' => canGet( 5 , FOOT)
) ,
'vas' => canGet( 11 , FOOT) ,
'isa' => canGet( 5 , FOOT) ,
'ras' => canGet( 7 , BUS)
) ,
'nov' => canGet( 7 , BUS) ,
'sen' => canGet( 3 , FOOT)
) ,
'vas' => canGet( 7 , SUBWAY) ,
'sen' => canGet( 3 , SUBWAY) ,
'dvo' => canGet( 6 , FOOT) ,
'gor' => canGet( 6 , SUBWAY) ,
'let' => canGet( 7 , FOOT) ,
'vla' => canGet( 7 , FOOT)
) ,
'ras' => canGet( 3 , FOOT) ,
'spo' => canGet( 7 , SUBWAY) ,
'gos' => canGet( 3 , SUBWAY) ,
'vla' => canGet( 4 , SUBWAY) ,
'vit' => canGet( 2 , SUBWAY) ,
'teh' => canGet( 3 , SUBWAY)
) ,
'sen' => canGet( 4 , SUBWAY) ,
'gos' => canGet( 7 , FOOT) ,
'vit' => canGet( 3 , SUBWAY)
) ,
'sen' => canGet( 2 , SUBWAY) ,
'teh' => canGet( 2 , SUBWAY) ,
'vla' => canGet( 3 , SUBWAY)
) ,
'sen' => canGet( 3 , SUBWAY) ,
'vit' => canGet( 2 , SUBWAY)
) ,
'' => canGet( 0 , SUBWAY)
)
) ;
/*
* Чтобы не писать много раз array('time' => ..., 'by' => ...), используем функцию.
* «canGet» переводится как «можно попасть»
*/
function canGet( $time , $byWhat )
{
'time' => $time ,
'by' => $byWhat
) ;
}
function makeOneStep( $paths , $pathDone , $time , $tempTime , $point , $target )
{
static $allTimes ;
static $allPaths ;
static $results ;
$pathDone [ ] = $point ;
$time += $tempTime ;
if ( $point == $target ) {
$allTimes [ ] = $time ;
$allPaths [ ] = $pathDone ;
$results [ 'times' ] = $allTimes ;
$results [ 'paths' ] = $allPaths ;
}
foreach ( $paths [ $point ] as $station => $pathInfo ) {
$tempTime = $pathInfo [ 'time' ] ;
$point = $station ;
makeOneStep( $paths , $pathDone , $time , $tempTime , $point , $target ) ;
}
}
return $results ;
}
$routes = makeOneStep( $paths , $pathDone , $time , $tempTime , $startPoint , $endPoint ) ;
$fastestTime = min ( $routes [ 'times' ] ) ; $fastestPath = $routes [ 'paths' ] [ array_search ( $fastestTime , $routes [ 'times' ] ) ] ;
echo "Начальная точка: \" $pointNames [$startPoint ]\" \n " ;
$i = 1 ;
$oneStep = $paths [ $fastestPath [ $i - 1 ] ] [ $fastestPath [ $i ] ] ;
for ( $i ; $i < count ( $fastestPath ) ; $i ++ ) { echo "Из нее {$transportName [$oneStep ['by']]} до точки " .
"\" {$pointNames [$fastestPath [$i ]]}\" {$oneStep['time']} мин.\n " ;
}
echo "В итоге ты попадешь в точку \" $pointNames [$endPoint ]\" за $fastestTime мин. Приятной поездки!" ;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0gMSk7CgpkZWZpbmUoJ1NVQldBWScsICdzdWInKTsKZGVmaW5lKCdGT09UJywgJ2Zvb3QnKTsKZGVmaW5lKCdCVVMnLCAnYnVzJyk7CgokdHJhbnNwb3J0TmFtZSA9IGFycmF5KAogICAgU1VCV0FZID0+ICfQtdC00LXRiNGMINC90LAg0LzQtdGC0YDQvicsCiAgICBGT09UID0+ICfQuNC00LXRiNGMINC/0LXRiNC60L7QvCcsCiAgICBCVVMgPT4gJ9C10LTQtdGI0Ywg0L3QsCDQsNCy0YLQvtCx0YPRgdC1JwopOwoKJHN0YXJ0UG9pbnQgPSAncGV0JzsgLy8g0J/QtdGC0YDQvtCz0YDQsNC00YHQutCw0Y8KJGVuZFBvaW50ID0gJ25vdic7IC8vINCd0L7QstCw0Y8g0JPQvtC70LvQsNC90LTQuNGPCiRwYXRoRG9uZSA9IFtdOwokdGltZSA9IDA7CiR0ZW1wVGltZSA9IDA7CgokcG9pbnROYW1lcyA9IGFycmF5KAogICAgJ3BldCcgPT4gJ9GB0YIuINC8LiDQn9C10YLRgNC+0LPRgNCw0LTRgdC60LDRjycsCiAgICAnY2hrJyA9PiAn0YHRgi4g0LwuINCn0LrQsNC70L7QstGB0LrQsNGPJywKICAgICdnb3InID0+ICfRgdGCLiDQvC4g0JPQvtGA0YzQutC+0LLRgdC60LDRjycsCiAgICAnc3BvJyA9PiAn0YHRgi4g0LwuINCh0L/QvtGA0YLQuNCy0L3QsNGPJywKICAgICd2YXMnID0+ICfRgdGCLiDQvC4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ICdwZXQnID0+IGNhbkdldCgzLCBCVVMpLAogICAgICAgICdrcmUnID0+IGNhbkdldCg1LCBGT09UKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoNiwgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3NwbycgPT4gYXJyYXkoCiAgICAgICAgJ2NoaycgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZhcycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzZW4nID0+IGNhbkdldCg3LCBTVUJXQVkpCiAgICApLAogICAgCiAgICAndmFzJyA9PiBhcnJheSgKICAgICAgICAnc3BvJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ25vdicgPT4gY2FuR2V0KDExLCBGT09UKQogICAgKSwKICAgIAogICAgJ2tyZScgPT4gYXJyYXkoCiAgICAgICAgJ2dvcicgPT4gY2FuR2V0KDUsIEZPT1QpCiAgICApLAogICAgCiAgICAnbGV0JyA9PiBhcnJheSgKICAgICAgICAnZHZvJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgCiAgICAnZHZvJyA9PiBhcnJheSgKICAgICAgICAnaXNhJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdsZXQnID0+IGNhbkdldCg2LCBGT09UKQogICAgKSwKICAgIAogICAgJ2lzYScgPT4gYXJyYXkoCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdub3YnID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgIAogICAgJ25vdicgPT4gYXJyYXkoCiAgICAgICAgJ3ZhcycgPT4gY2FuR2V0KDExLCBGT09UKSwKICAgICAgICAnaXNhJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ3JhcycgPT4gY2FuR2V0KDcsIEJVUykKICAgICksCiAgICAKICAgICdyYXMnID0+IGFycmF5KAogICAgICAgICdub3YnID0+IGNhbkdldCg3LCBCVVMpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBGT09UKQogICAgKSwKICAgIAogICAgJ2dvcycgPT4gYXJyYXkoCiAgICAgICAgJ3ZhcycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3InID0+IGNhbkdldCg2LCBTVUJXQVkpLAogICAgICAgICdsZXQnID0+IGNhbkdldCg3LCBGT09UKSwKICAgICAgICAndmxhJyA9PiBjYW5HZXQoNywgRk9PVCkKICAgICksCiAgICAKICAgICdzZW4nID0+IGFycmF5KAogICAgICAgICdyYXMnID0+IGNhbkdldCgzLCBGT09UKSwKICAgICAgICAnc3BvJyA9PiBjYW5HZXQoNywgU1VCV0FZKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAndmxhJyA9PiBjYW5HZXQoNCwgU1VCV0FZKSwKICAgICAgICAndml0JyA9PiBjYW5HZXQoMiwgU1VCV0FZKSwKICAgICAgICAndGVoJyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3ZsYScgPT4gYXJyYXkoCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIEZPT1QpLAogICAgICAgICd2aXQnID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAndml0JyA9PiBhcnJheSgKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoMiwgU1VCV0FZKSwKICAgICAgICAndGVoJyA9PiBjYW5HZXQoMiwgU1VCV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