<?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 , $lowerTime = INF)
{
$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 , $lowerTime ) ;
if ( ! isset ( $newPath [ 'time' ] ) ) { CONTINUE ;
}
if ( is_infinite ( $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+0LLQsNGPINCT0L7Qu9C70LDQvdC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0YInCik7CgokcGF0aHMgPSBhcnJheSgKICAgICdwZXQnID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ2NoaycgPT4gYXJyYXkoCiAgICAgICAgJ3BldCcgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzcG8nID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAnZ29yJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMywgQlVTKSwKICAgICAgICAna3JlJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIFNVQldBWSkKICAgICksCiAgICAKICAgICdzcG8nID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoNywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3ZhcycgPT4gYXJyYXkoCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdub3YnID0+IGNhbkdldCgxMSwgRk9PVCkKICAgICksCiAgICAKICAgICdrcmUnID0+IGFycmF5KAogICAgICAgICdnb3InID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgIAogICAgJ2xldCcgPT4gYXJyYXkoCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBGT09UKQogICAgKSwKICAgIAogICAgJ2R2bycgPT4gYXJyYXkoCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNiwgRk9PVCkKICAgICksCiAgICAKICAgICdpc2EnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNSwgRk9PVCkKICAgICksCiAgICAKICAgICdub3YnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMSwgRk9PVCksCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdyYXMnID0+IGNhbkdldCg3LCBCVVMpCiAgICApLAogICAgCiAgICAncmFzJyA9PiBhcnJheSgKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNywgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoMywgRk9PVCkKICAgICksCiAgICAKICAgICdnb3MnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoNiwgU1VCV0FZKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNywgRk9PVCksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgCiAgICAnc2VuJyA9PiBhcnJheSgKICAgICAgICAncmFzJyA9PiBjYW5HZXQoMywgRk9PVCksCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ3ZpdCcgPT4gY2FuR2V0KDIsIFNVQldBWSksCiAgICAgICAgJ3RlaCcgPT4gY2FuR2V0KDMsIFNVQldBWS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7CiAgICBpZiAoaXNzZXQoJHBhdGhzWyRzdGFydFBvaW50XVskZW5kUG9pbnRdKSkgewogICAgICAgICRwYXRoRG9uZVtdID0gJGVuZFBvaW50OwogICAgICAgICR0aW1lICs9ICRwYXRoc1skc3RhcnRQb2ludF1bJGVuZFBvaW50XVsndGltZSddOwogICAgICAgIHJldHVybiAkcmVzdWx0ID0gYXJyYXkoCiAgICAgICAgICAgICdwYXRoJyA9PiAkcGF0aERvbmUsCiAgICAgICAgICAgICd0aW1lJyA9PiAkdGltZQogICAgICAgICk7CiAgICB9CiAgICAkc2hvcnRlc3QgPSBhcnJheSgpOwogICAgZm9yZWFjaCAoJHBhdGhzWyRzdGFydFBvaW50XSBhcyAkc3RhdGlvbk5hbWUgPT4gJHN0YXRpb25JbmZvKSB7CiAgICAgICAgaWYgKGluX2FycmF5KCRzdGF0aW9uTmFtZSwgJHBhdGhEb25lKSkgewogICAgICAgICAgICBDT05USU5VRTsKICAgICAgICB9CiAgICAgICAgJHhUaW1lID0gJHRpbWU7CiAgICAgICAgJHhUaW1lICs9ICRwYXRoc1skc3RhcnRQb2ludF1bJHN0YXRpb25OYW1lXVsndGltZSddOwogICAgICAgICRuZXdQYXRoID0gbWFrZU9uZVN0ZXAoJHBhdGhzLCAkc3RhdGlvbk5hbWUsICRlbmRQb2ludCwgJHBhdGhEb25lLCAkeFRpbWUsICRsb3dlclRpbWUpOwogICAgICAgIGlmICghaXNzZXQoJG5ld1BhdGhbJ3RpbWUnXSkpIHsKICAgICAgICAgICAgQ09OVElOVUU7CiAgICAgICAgfQogICAgICAgIGlmIChpc19pbmZpbml0ZSgkbG93ZXJUaW1lKSB8fCAoJG5ld1BhdGhbJ3RpbWUnXSA8ICRsb3dlclRpbWUpKSB7CiAgICAgICAgICAgICRsb3dlclRpbWUgPSAkbmV3UGF0aFsndGltZSddOwogICAgICAgICAgICAkc2hvcnRlc3QgID0gJG5ld1BhdGg7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuICRza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