<?php
header ( "Content-Type: text/plain; charset=utf-8" ) ; ?>
<?php
/* http://d...content-available-to-author-only...2.net/ */
SUBWAY => 'едешь на метро' ,
FOOT => 'идешь пешком' ,
BUS => 'едешь на автобусе'
) ;
$startPoint = 'pet' ; // Петроградская
$endPoint = 'nov' ; // Новая Голландия
'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)
)
) ;
/* Чтобы не писать много раз array('time' => ..., 'by' => ...), используем функцию.
«canGet» переводится как «можно попасть» */
function canGet( $time , $byWhat )
{
'time' => $time ,
'by' => $byWhat
) ;
}
$time = 0 ;
$lowerTime = 5000 ;
function makeOneStep( $paths , $startPoint , $endPoint , $time = 0 , $lowerTime = 5000 , $pathDone )
{
$pathDone [ ] = $startPoint ;
if ( isset ( $paths [ $startPoint ] [ $endPoint ] ) ) { $pathDone [ ] = $endPoint ;
$time += $paths [ $startPoint ] [ $endPoint ] [ 'time' ] ;
$result [ 'path' ] = $pathDone ;
$result [ 'time' ] = $time ;
return $result ;
}
foreach ( $paths [ $startPoint ] as $stationName => $stationInfo ) {
if ( ! in_array ( $stationName , $pathDone ) ) { $xTime = $time ;
$pointTime = $paths [ $startPoint ] [ $stationName ] [ 'time' ] ;
$xTime += $pointTime ;
$newPath = makeOneStep( $paths , $stationName , $endPoint , $xTime , $lowerTime , $pathDone ) ;
if ( ! isset ( $newPath [ 'time' ] ) ) {
CONTINUE ;
}
if ( ( $newPath [ 'time' ] < $lowerTime ) ) {
$lowerTime = $newPath [ 'time' ] ;
$shortest = $newPath ;
}
}
}
$result = $shortest ;
return $result ;
}
$path = makeOneStep( $paths , $startPoint , $endPoint , $time , $lowerTime , $pathDone ) ;
$text = "Маршрут построен: \n Начальная точка " ;
$i = 0 ;
for ( $i = 0 ; $i < count ( $path [ 'path' ] ) ; $i ++ ) { $point = $path [ 'path' ] [ $i ] ;
if ( $i == 0 ) {
$text .= "«{$pointNames [$point ]}»\n " ;
}
else {
$byWhat = $paths [ $lastPoint ] [ $point ] [ 'by' ] ;
$text .= "Из неё {$transportName [$byWhat ]} «{$pointNames [$point ]}» за {$paths [$lastPoint ][$point ]['time']} мин\n " ;
}
$lastPoint = $point ;
}
$text .= "В итоге ты попадешь в «{$pointNames [$point ]}» за {$path['time']} мин\n " ;
echo $text ;
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKPz4KIAo8P3BocAptYl9pbnRlcm5hbF9lbmNvZGluZygiVVRGLTgiKTsKZXJyb3JfcmVwb3J0aW5nKC0xKTsKLyogaHR0cDovL2QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLjIubmV0LyAqLwpkZWZpbmUoJ1NVQldBWScsICdzdWInKTsKZGVmaW5lKCdGT09UJywgJ2Zvb3QnKTsKZGVmaW5lKCdCVVMnLCAnYnVzJyk7CiR0cmFuc3BvcnROYW1lID0gYXJyYXkoCiAgICBTVUJXQVkgPT4gJ9C10LTQtdGI0Ywg0L3QsCDQvNC10YLRgNC+JywKICAgIEZPT1QgPT4gJ9C40LTQtdGI0Ywg0L/QtdGI0LrQvtC8JywKICAgIEJVUyA9PiAn0LXQtNC10YjRjCDQvdCwINCw0LLRgtC+0LHRg9GB0LUnCik7CiRzdGFydFBvaW50ID0gJ3BldCc7IC8vINCf0LXRgtGA0L7Qs9GA0LDQtNGB0LrQsNGPCiRlbmRQb2ludCAgID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C90L7Qu9C+0LPQuNGH0LXRgdC60LjQuSDQmNC90YHRgtC40YLRg9GCJwopOwokcGF0aHMgPSBhcnJheSgKICAgICdwZXQnID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ2NoaycgPT4gYXJyYXkoCiAgICAgICAgJ3BldCcgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzcG8nID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAnZ29yJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMywgQlVTKSwKICAgICAgICAna3JlJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIFNVQldBWSkKICAgICksCiAgICAKICAgICdzcG8nID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoNywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3ZhcycgPT4gYXJyYXkoCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdub3YnID0+IGNhbkdldCgxMSwgRk9PVCkKICAgICksCiAgICAKICAgICdrcmUnID0+IGFycmF5KAogICAgICAgICdnb3InID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgIAogICAgJ2xldCcgPT4gYXJyYXkoCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBGT09UKQogICAgKSwKICAgIAogICAgJ2R2bycgPT4gYXJyYXkoCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNiwgRk9PVCkKICAgICksCiAgICAKICAgICdpc2EnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNSwgRk9PVCkKICAgICksCiAgICAKICAgICdub3YnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMSwgRk9PVCksCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdyYXMnID0+IGNhbkdldCg3LCBCVVMpCiAgICApLAogICAgCiAgICAncmFzJyA9PiBhcnJheSgKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNywgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoMywgRk9PVCkKICAgICksCiAgICAKICAgICdnb3MnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoNiwgU1VCV0FZKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNywgRk9PVCksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgCiAgICAnc2VuJyA9PiBhcnJheSgKICAgICAgICAncmFzJyA9PiBjYW5HZXQoMywgRk9PVCksCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ3ZpdCcgPT4gY2FuR2V0KDIsIFNVQld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