<?php
header ( "Content-Type: text/plain; charset=utf-8" ) ;
/* 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
) ;
return $result ;
}
foreach ( $paths [ $startPoint ] as $stationName => $stationInfo ) {
if ( in_array ( $stationName , $pathDone ) ) { CONTINUE ;
}
$xTime = $time + $paths [ $startPoint ] [ $stationName ] [ 'time' ] ;
$newPath = makeOneStep( $paths , $stationName , $endPoint , $pathDone , $xTime ) ;
if ( $newPath ) {
if ( ( $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 ;
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoIlVURi04Iik7CgplcnJvcl9yZXBvcnRpbmcoLTEpOwovKiBodHRwOi8vZC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uMi5uZXQvICovCgpkZWZpbmUoJ1NVQldBWScsICdzdWInKTsKZGVmaW5lKCdGT09UJywgJ2Zvb3QnKTsKZGVmaW5lKCdCVVMnLCAnYnVzJyk7CgokdHJhbnNwb3J0TmFtZSA9IGFycmF5KAogICAgU1VCV0FZID0+ICfQtdC00LXRiNGMINC90LAg0LzQtdGC0YDQvicsCiAgICBGT09UID0+ICfQuNC00LXRiNGMINC/0LXRiNC60L7QvCcsCiAgICBCVVMgPT4gJ9C10LTQtdGI0Ywg0L3QsCDQsNCy0YLQvtCx0YPRgdC1JwopOwoKJHN0YXJ0UG9pbnQgPSAncGV0JzsgLy8g0J/QtdGC0YDQvtCz0YDQsNC00YHQutCw0Y8KJGVuZFBvaW50ICAgPSAnbm92JzsgLy8g0J3QvtCy0LDRjyDQk9C+0LvQu9Cw0L3QtNC40Y8KCiRwb2ludE5hbWVzID0gYXJyYXkoCiAgICAncGV0JyA9PiAn0YHRgi4g0LwuINCf0L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Y2hrJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcicgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAKICAgICdjaGsnID0+IGFycmF5KAogICAgICAgICdwZXQnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc3BvJyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ2dvcicgPT4gYXJyYXkoCiAgICAgICAgJ3BldCcgPT4gY2FuR2V0KDMsIEJVUyksCiAgICAgICAgJ2tyZScgPT4gY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg2LCBTVUJXQVkpCiAgICApLAogICAgCiAgICAnc3BvJyA9PiBhcnJheSgKICAgICAgICAnY2hrJyA9PiBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAndmFzJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDcsIFNVQldBWSkKICAgICksCiAgICAKICAgICd2YXMnID0+IGFycmF5KAogICAgICAgICdzcG8nID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoNywgU1VCV0FZKSwKICAgICAgICAnbm92JyA9PiBjYW5HZXQoMTEsIEZPT1QpCiAgICApLAogICAgCiAgICAna3JlJyA9PiBhcnJheSgKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoNSwgRk9PVCkKICAgICksCiAgICAKICAgICdsZXQnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoNywgRk9PVCkKICAgICksCiAgICAKICAgICdkdm8nID0+IGFycmF5KAogICAgICAgICdpc2EnID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2xldCcgPT4gY2FuR2V0KDYsIEZPT1QpCiAgICApLAogICAgCiAgICAnaXNhJyA9PiBhcnJheSgKICAgICAgICAnZHZvJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ25vdicgPT4gY2FuR2V0KDUsIEZPT1QpCiAgICApLAogICAgCiAgICAnbm92JyA9PiBhcnJheSgKICAgICAgICAndmFzJyA9PiBjYW5HZXQoMTEsIEZPT1QpLAogICAgICAgICdpc2EnID0+IGNhbkdldCg1LCBGT09UKSwKICAgICAgICAncmFzJyA9PiBjYW5HZXQoNywgQlVTKQogICAgKSwKICAgIAogICAgJ3JhcycgPT4gYXJyYXkoCiAgICAgICAgJ25vdicgPT4gY2FuR2V0KDcsIEJVUyksCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDMsIEZPT1QpCiAgICApLAogICAgCiAgICAnZ29zJyA9PiBhcnJheSgKICAgICAgICAndmFzJyA9PiBjYW5HZXQoNywgU1VCV0FZKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAnZHZvJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcicgPT4gY2FuR2V0KDYsIFNVQldBWSksCiAgICAgICAgJ2xldCcgPT4gY2FuR2V0KDcsIEZPT1QpLAogICAgICAgICd2bGEnID0+IGNhbkdldCg3LCBGT09UKQogICAgKSwKICAgIAogICAgJ3NlbicgPT4gYXJyYXkoCiAgICAgICAgJ3JhcycgPT4gY2FuR2V0KDMsIEZPT1QpLAogICAgICAgICdzcG8nID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdnb3MnID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2bGEnID0+IGNhbkdldCg0LCBTVUJXQVkpLAogICAgICAgICd2aXQnID0+IGNhbkdldCgyLCBTVUJXQVkpLAogICAgICAgICd0ZWgnID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAndmxhJyA9PiBhcnJheSgKICAgICAgICAnc2VuJ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G9pbnRdKSkgewogICAgICAgICRwYXRoRG9uZVtdID0gJGVuZFBvaW50OwogICAgICAgICR0aW1lICs9ICRwYXRoc1skc3RhcnRQb2ludF1bJGVuZFBvaW50XVsndGltZSddOwogICAgICAgICRyZXN1bHQgPSBhcnJheSgKICAgICAgICAgICAgJ3BhdGgnID0+ICRwYXRoRG9uZSwKICAgICAgICAgICAgJ3RpbWUnID0+ICR0aW1lCiAgICAgICAgKTsKICAgICAgICByZXR1cm4gJHJlc3VsdDsKICAgIH0KICAgICRzaG9ydGVzdCA9IGFycmF5KCk7CiAgICBmb3JlYWNoICgkcGF0aHNbJHN0YXJ0UG9pbnRdIGFzICRzdGF0aW9uTmFtZSA9PiAkc3RhdGlvbkluZm8pIHsKICAgICAgICBpZiAoaW5fYXJyYXkoJHN0YXRpb25OYW1lLCAkcGF0aERvbmUpKSB7CiAgICAgICAgICAgIENPTlRJTlVFOwogICAgICAgIH0KICAgICAgICAkeFRpbWUgICA9ICR0aW1lICsgJHBhdGhzWyRzdGFydFBvaW50XVskc3RhdGlvbk5hbWVdWyd0aW1lJ107CiAgICAgICAgJG5ld1BhdGggPSBtYWtlT25lU3RlcCgkcGF0aHMsICRzdGF0aW9uTmFtZSwgJGVuZFBvaW50LCAkcGF0aERvbmUsICR4VGltZSk7CiAgICAgICAgaWYgKCRuZXdQYXRoKSB7CiAgICAgICAgICAgIGlmICgoJG5ld1BhdGhbJ3RpbWUnXSA8ICRsb3dlclRpbWUpKSB7CiAgICAgICAgICAgICAgICAkbG93ZXJUaW1lID0gJG5ld1BhdGhbJ3RpbWUnXTsKICAgICAgICAgICAgICAgICRzaG9ydGVzdCAgPSAkbmV3UGF0aDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAkc2hvcnRlc3Q7Cn0KJHBhdGggPSBtYWtlT25lU3RlcCgkcGF0aHMsICRzdGFydFBvaW50LCAkZW5kUG9pbnQsICRwYXRoRG9uZSk7CgokdGV4dCA9ICLQnNCw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