<?php
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) {
return array('time' => $time, 'by' => $byWhat); }
function makeOneStep($pathDone, $time, $point, $target, $paths) {
if (isset($paths[$point][$target])) { $result['time'] = $time + $paths[$point][$target]['time'];
$result['path'] = array_merge($pathDone, $pointNames[$target]); return $result;
} else {
foreach($paths[$point] as $key => $value) {
if(isset($paths[$key][$target])) { $newStep = makeOneStep($pathDone, $time, $point, $paths[$key], $path);
return makeOneStep
($newStep['path'], $newStep['time'], end($newStep['path']), $target, $path); }
}
}
}
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpkZWZpbmUoJ1NVQldBWScsICdzdWInKTsKZGVmaW5lKCdGT09UJywgJ2Zvb3QnKTsKZGVmaW5lKCdCVVMnLCAnYnVzJyk7CgokdHJhbnNwb3J0TmFtZSA9IGFycmF5KAogICAgU1VCV0FZICA9PiAgJ9C10LTQtdGI0Ywg0L3QsCDQvNC10YLRgNC+JywKICAgIEZPT1QgICAgPT4gICfQuNC00LXRiNGMINC/0LXRiNC60L7QvCcsCiAgICBCVVMgICAgID0+ICAn0LXQtNC10YjRjCDQvdCwINCw0LLRgtC+0LHRg9GB0LUnCik7Cgokc3RhcnRQb2ludCA9ICdwZXQnOyAvLyDQn9C10YLRgNC+0LPRgNCw0LTRgdC60LDRjwokZW5kUG9pbnQgPSAnbm92JzsgLy8g0J3QvtCy0LDRjyDQk9C+0LvQu9Cw0L3QtNC40Y8KCiRwb2ludE5hbWVzID0gYXJyYXkoCiAgICAncGV0J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RgtC40YLRg9GCJwopOwoKJHBhdGhzID0gYXJyYXkoCiAgICAncGV0JyAgID0+ICBhcnJheSgKICAgICAgICAnY2hrJyAgID0+ICBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcicgICA9PiAgY2FuR2V0KDMsIFNVQldBWSkKICAgICksCgogICAgJ2NoaycgICA9PiAgYXJyYXkoCiAgICAgICAgJ3BldCcgICA9PiAgY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzcG8nICAgPT4gIGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAoKICAgICdnb3InICAgPT4gIGFycmF5KAogICAgICAgICdwZXQnICAgPT4gIGNhbkdldCgzLCBCVVMpLAogICAgICAgICdrcmUnICAgPT4gIGNhbkdldCg1LCBGT09UKSwKICAgICAgICAnZ29zJyAgID0+ICBjYW5HZXQoNiwgU1VCV0FZKQogICAgKSwKCiAgICAnc3BvJyAgID0+ICBhcnJheSgKICAgICAgICAnY2hrJyAgID0+ICBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAndmFzJyAgID0+ICBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NlbicgICA9PiAgY2FuR2V0KDcsIFNVQldBWSkKICAgICksCgogICAgJ3ZhcycgICA9PiAgYXJyYXkoCiAgICAgICAgJ3NwbycgICA9PiAgY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdnb3MnICAgPT4gIGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdub3YnICAgPT4gIGNhbkdldCgxMSwgRk9PVCkKICAgICksCgogICAgJ2tyZScgICA9PiAgYXJyYXkoCiAgICAgICAgJ2dvcicgICA9PiAgY2FuR2V0KDUsIEZPT1QpCiAgICApLAoKICAgICdsZXQnICAgPT4gIGFycmF5KAogICAgICAgICdkdm8nICAgPT4gIGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29zJyAgID0+ICBjYW5HZXQoNywgRk9PVCkKICAgICksCgogICAgJ2R2bycgICA9PiAgYXJyYXkoCiAgICAgICAgJ2lzYScgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnICAgPT4gIGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbGV0JyAgID0+ICBjYW5HZXQoNiwgRk9PVCkKICAgICksCgogICAgJ2lzYScgICA9PiAgYXJyYXkoCiAgICAgICAgJ2R2bycgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdub3YnICAgPT4gIGNhbkdldCg1LCBGT09UKQogICAgKSwKCiAgICAnbm92JyAgID0+ICBhcnJheSgKICAgICAgICAndmFzJyAgID0+ICBjYW5HZXQoMTEsIEZPT1QpLAogICAgICAgICdpc2EnICAgPT4gIGNhbkdldCg1LCBGT09UKSwKICAgICAgICAncmFzJyAgID0+ICBjYW5HZXQoNywgQlVTKQogICAgKSwKCiAgICAncmFzJyAgID0+ICBhcnJheSgKICAgICAgICAnbm92JyAgID0+ICBjYW5HZXQoNywgQlVTKSwKICAgICAgICAnc2VuJyAgID0+ICBjYW5HZXQoMywgRk9PVCkKICAgICksCgogICAgJ2dvcycgICA9PiAgYXJyYXkoCiAgICAgICAgJ3ZhcycgICA9PiAgY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ3NlbicgICA9PiAgY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ2R2bycgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3InICAgPT4gIGNhbkdldCg2LCBTVUJXQVkpLAogICAgICAgICdsZXQnICAgPT4gIGNhbkdldCg3LCBGT09UKSwKICAgICAgICAndmxhJyAgID0+ICBjYW5HZXQoNywgRk9PVCkgICAgICAgIAogICAgKSwKCiAgICAnc2VuJyAgID0+ICBhcnJheSgKICAgICAgICAncmFzJyAgID0+ICBjYW5HZXQoMywgRk9PVCksCiAgICAgICAgJ3NwbycgICA9PiAgY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDMsIFNV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