<?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 oneStep( $paths , $pathDone , $time , $point , $target )
{
if ( ! $paths [ $point ] [ $target ] ) {
foreach ( $paths [ $point ] as $key => $val ) {
continue ;
}
$pathDone [ ] = $key ;
$time = $time + $paths [ $point ] [ $key ] [ 'time' ] ;
$container = oneStep( $paths , $pathDone , $time , $key , $target ) ;
if ( $time > $container [ 'time' ] ) {
continue ;
}
return $container ;
}
}
else {
$result [ 'path' ] = $pathDone ;
$result [ 'time' ] = $paths [ $point ] [ $target ] [ 'time' ] + $time ;
$time = 0 ;
return $result ;
}
}
$testvar = oneStep( $paths , $testar , 0 , 'vas' , 'teh' ) ;
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Ci8qIGh0dHA6Ly9kLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi4yLm5ldC8gKi8KCmRlZmluZSgnU1VCV0FZJywgJ3N1YicpOwpkZWZpbmUoJ0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QuNGPJywKICAgICdyYXMnID0+ICfQlNC+0Lwg0KDQsNGB0LrQvtC70YzQvdC40LrQvtCy0LAnLAogICAgJ2dvcycgPT4gJ9CT0L7RgdGC0LjQvdGL0Lkg0JTQstC+0YAnLAogICAgJ3NlbicgPT4gJ9Ch0LXQvdC90LDRjyDQn9C70L7RidCw0LTRjCcsCiAgICAndmxhJyA9PiAn0YHRgi4g0LwuINCS0LvQsNC00LjQvNC40YDRgdC60LDRjycsCiAgICAndml0JyA9PiAn0JLQuNGC0LXQsdGB0LrQuNC5INCy0L7QutC30LDQuycsCiAgICAndGVoJyA9PiAn0KLQtdGF0L3QvtC70L7Qs9C40YfQtdGB0LrQuNC5INCY0L3RgdGC0LjRgtGD0YInCik7CgokcGF0aHMgPSBhcnJheSgKICAgICdwZXQnID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ2NoaycgPT4gYXJyYXkoCiAgICAgICAgJ3BldCcgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzcG8nID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAnZ29yJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMywgQlVTKSwKICAgICAgICAna3JlJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIFNVQldBWSkKICAgICksCiAgICAKICAgICdzcG8nID0+IGFycmF5KAogICAgICAgICdjaGsnID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoNywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3ZhcycgPT4gYXJyYXkoCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdub3YnID0+IGNhbkdldCgxMSwgRk9PVCkKICAgICksCiAgICAKICAgICdrcmUnID0+IGFycmF5KAogICAgICAgICdnb3InID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgIAogICAgJ2xldCcgPT4gYXJyYXkoCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBGT09UKQogICAgKSwKICAgIAogICAgJ2R2bycgPT4gYXJyYXkoCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNiwgRk9PVCkKICAgICksCiAgICAKICAgICdpc2EnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNSwgRk9PVCkKICAgICksCiAgICAKICAgICdub3YnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCgxMSwgRk9PVCksCiAgICAgICAgJ2lzYScgPT4gY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdyYXMnID0+IGNhbkdldCg3LCBCVVMpCiAgICApLAogICAgCiAgICAncmFzJyA9PiBhcnJheSgKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNywgQlVTKSwKICAgICAgICAnc2VuJyA9PiBjYW5HZXQoMywgRk9PVCkKICAgICksCiAgICAKICAgICdnb3MnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoNiwgU1VCV0FZKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNywgRk9PVCksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgCiAgICAnc2VuJyA9PiBhcnJheSgKICAgICAgICAncmFzJyA9PiBjYW5HZXQoMywgRk9PVCksCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ3ZpdCcgPT4gY2FuR2V0KDIsIFNVQldBWSksCiAgICAgICAgJ3RlaCcgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAKICAgICd2bGEnID0+IGFycmF5KAogICAgICAgICdzZW4nID0+IGNhbkdldCg0LCBTVUJXQVkpLAogICAgICAgICdnb3MnID0+IGNhbkdldCg3LCBGT09UKSwKICAgICAgICAndml0JyA9PiBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3ZpdCcgPT4gYXJyYXkoCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDIsIFNVQldBWSksCiAgICAgICAgJ3RlaCcgPT4gY2FuR2V0KDIsIFNVQldBWSksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAKICAgICd0ZWgnID0+IGFycmF5KAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2aXQnID0+IGNhbkdldCgyLCBTVUJXQVkpCiAgICApCik7CgovKiDQp9GC0L7QsdGLINC90LUg0L/QuNGB0LDRgtGMINC80L3QvtCz0L4g0YDQsNC3IGFycmF5KCd0aW1lJyA9PiAuLi4sICdieScgPT4gLi4uKSwg0LjRgdC/0L7Qu9GM0LfRg9C10Lwg0YTRg9C90LrRhtC40Y4uIArCq2NhbkdldMK7INC/0LXRgNC10LLQvtC00LjRgtGB0Y8g0LrQsNC6IMKr0LzQvtC20L3QviDQv9C+0L/QsNGB0YLRjMK7ICovCmZ1bmN0aW9uIGNhbkdldCgkdGltZSwgJGJ5V2hhdCkKewogICAgcmV0dXJuIGFycmF5KAogICAgICAgICd0aW1lJyA9PiAkdGltZSwKICAgICAgICAnYnknID0+ICRieVdoYXQKICAgICk7Cn0KCmZ1bmN0aW9uIG9uZVN0ZXAoJHBhdGhzLCAkcGF0aERvbmUsICR0aW1lLCAkcG9pbnQsICR0YXJnZXQpCnsKICAgICRyZXN1bHQgPSBhcnJheSgpOwogICAgCiAgICBpZiAoISRwYXRoc1skcG9pbnRdWyR0YXJnZXRdKSB7CiAgICAgICAgZm9yZWFjaCAoJHBhdGhzWyRwb2ludF0gYXMgJGtleSA9PiAkdmFsKSB7CiAgICAgICAgICAgIGlmIChpbl9hcnJheSgka2V5LCAkcGF0aERvbmUpKSB7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgJHBhdGhEb25lW10gPSAka2V5OwogICAgICAgICAgICAkdGltZSAgICAgICA9ICR0aW1lICsgJHBhdGhzWyRwb2ludF1bJGtleV1bJ3RpbWUnXTsKICAgICAgICAgICAgJGNvbnRhaW5lciAgPSBvbmVTdGVwKCRwYXRocywgJHBhdGhEb25lLCAkdGltZSwgJGtleSwgJHRhcmdldCk7CiAgICAgICAgICAgIAogICAgICAgICAgICBpZiAoJHRpbWUgPiAkY29udGFpbmVyWyd0aW1lJ10pIHsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICByZXR1cm4gJGNvbnRhaW5lcjsKICAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgfQogICAgCiAgICBlbHNlIHsKICAgICAgICAKICAgICAgICAKICAgICAgICAkcmVzdWx0WydwYXRoJ10gPSAkcGF0aERvbmU7CiAgICAgICAgJHJlc3VsdFsndGltZSddID0gJHBhdGhzWyRwb2ludF1bJHRhcmdldF1bJ3RpbWUnXSArICR0aW1lOwogICAgICAgICRwYXRoRG9uZSAgICAgICA9IGFycmF5KCk7CiAgICAgICAgJHRpbWUgICAgICAgICAgID0gMDsKICAgICAgICByZXR1cm4gJHJlc3VsdDsKICAgICAgICAKICAgIH0KfQokdGVzdGFyICA9IGFycmF5KCk7CiR0ZXN0dmFyID0gb25lU3RlcCgkcGF0aHMsICR0ZXN0YXIsIDAsICd2YXMnLCAndGVoJyk7CnZhcl9kdW1wKCR0ZXN0dmFyKTs=