<?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
) ;
}
function makeOneStep( $paths , $startPoint , $endPoint , $pathDone , $time = 0 )
{
$pathDone [ ] = $startPoint ;
if ( isset ( $paths [ $startPoint ] [ $endPoint ] ) ) { $pathDone [ ] = $endPoint ;
$time += $paths [ $startPoint ] [ $endPoint ] [ 'time' ] ;
'path' => $pathDone ,
'time' => $time
) ;
}
foreach ( $paths [ $startPoint ] as $stationName => $stationInfo ) {
if ( in_array ( $stationName , $pathDone ) ) { CONTINUE ;
}
$xTime = $time ;
$xTime += $paths [ $startPoint ] [ $stationName ] [ 'time' ] ;
$newPath = makeOneStep( $paths , $stationName , $endPoint , $pathDone , $xTime ) ;
if ( $newPath ) {
if ( ! isset ( $lowerTime ) || ( $newPath [ 'time' ] < $lowerTime ) ) { $lowerTime = $newPath [ 'time' ] ;
$shortest = $newPath ;
}
}
}
return $shortest ;
}
$path = makeOneStep( $paths , $startPoint , $endPoint , $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 ;
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKPz4KIAo8P3BocAptYl9pbnRlcm5hbF9lbmNvZGluZygiVVRGLTgiKTsKCmVycm9yX3JlcG9ydGluZygtMSk7Ci8qIGh0dHA6Ly9kLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi4yLm5ldC8gKi8KCmRlZmluZSgnU1VCV0FZJywgJ3N1YicpOwpkZWZpbmUoJ0ZPT1QnLCAnZm9vdCcpOwpkZWZpbmUoJ0JVUycsICdidXMnKTsKCiR0cmFuc3BvcnROYW1lID0gYXJyYXkoCiAgICBTVUJXQVkgPT4gJ9C10LTQtdGI0Ywg0L3QsCDQvNC10YLRgNC+JywKICAgIEZPT1QgPT4gJ9C40LTQtdGI0Ywg0L/QtdGI0LrQvtC8JywKICAgIEJVUyA9PiAn0LXQtNC10YjRjCDQvdCwINCw0LLRgtC+0LHRg9GB0LUnCik7Cgokc3RhcnRQb2ludCA9ICdwZXQnOyAvLyDQn9C10YLRgNC+0LPRgNCw0LTRgdC60LDRjwokZW5kUG9pbnQgICA9ICdub3YnOyAvLyDQndC+0LLQsNGPINCT0L7Qu9C70LDQvdC00LjRjwoKJHBvaW50TmFtZXMgPSBhcnJheSgKICAgICdwZX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GFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ2NoaycgPT4gYXJyYXkoCiAgICAgICAgJ3BldCcgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzcG8nID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAnZ29yJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMywgQlVTKSwKICAgICAgICAna3JlJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIFNVQldBWSkKICAgICksCiAgICAKICAgICdzcG8nID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoNywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3ZhcycgPT4gYXJyYXkoCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdub3YnID0+IGNhbkdldCgxMSwgRk9PVCkKICAgICksCiAgICAKICAgICdrcmUnID0+IGFycmF5KAogICAgICAgICdnb3InID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgIAogICAgJ2xldCcgPT4gYXJyYXkoCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBGT09UKQogICAgKSwKICAgIAogICAgJ2R2bycgPT4gYXJyYXkoCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNiwgRk9PVCkKICAgICksCiAgICAKICAgICdpc2EnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNSwgRk9PVCkKICAgICksCiAgICAKICAgICdub3YnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMSwgRk9PVCksCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdyYXMnID0+IGNhbkdldCg3LCBCVVMpCiAgICApLAogICAgCiAgICAncmFzJyA9PiBhcnJheSgKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNywgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoMywgRk9PVCkKICAgICksCiAgICAKICAgICdnb3MnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoNiwgU1VCV0FZKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNywgRk9PVCksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgCiAgICAnc2VuJyA9PiBhcnJheSgKICAgICAgICAncmFzJyA9PiBjYW5HZXQoMywgRk9PVCksCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ3ZpdCcgPT4gY2FuR2V0KDIsIFNVQldBWSksCiAgICAgICAgJ3RlaCcgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAKICAgICd2bGEnID0+IGFycmF5KAogICAgICA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