<?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' => ...), используем функцию.
function canGet($time, $byWhat) {
return array('time' => $time, 'by' => $byWhat); }
function makeOneStep($paths, $pathDone, $time, $point, $target) {
$result = ['time', 'path'];
foreach ($paths[$point] as $path => $value) {
if ($path == $target) {
$result['path'] = $pathDone;
$result['time'] = $time + $value['time'];
return $result;
}
}
foreach ($paths[$point] as $path => $value) {
continue;
}
$time += $value['time'];
$point = $path;
return makeOneStep($paths, $pathDone, $time, $point, $target);
}
}
$pathDone = array('pet'); $time = 0;
$point = 'pet';
$target = 'nov';
$result = makeOneStep($paths, $pathDone, $time, $point, $target);
PD9waHAKCmRlZmluZSgnU1VCV0FZJywgJ3N1YicpOwpkZWZpbmUoJ0ZPT1QnLCAnZm9vdCcpOwpkZWZpbmUoJ0JVUycsICdidXMnKTsKCiR0cmFuc3BvcnROYW1lID0gYXJyYXkoCiAgICBTVUJXQVkgPT4gJ9C10LTQtdGI0Ywg0L3QsCDQvNC10YLRgNC+JywKICAgIEZPT1QgPT4gJ9C40LTQtdGI0Ywg0L/QtdGI0LrQvtC8JywKICAgIEJVUyA9PiAn0LXQtNC10YjRjCDQvdCwINCw0LLRgtC+0LHRg9GB0LUnCik7Cgokc3RhcnRQb2ludCA9ICdwZXQnOyAvLyDQn9C10YLRgNC+0LPRgNCw0LTRgdC60LDRjwokZW5kUG9pbnQgPSAnbm92JzsgLy8g0J3QvtCy0LDRjyDQk9C+0LvQu9Cw0L3QtNC40Y8KCiRwb2ludE5hbWVzID0gYXJyYXkoCiAgICAncGV0JyA9PiAn0YHRgi4g0LwuIN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gICAnY2hrJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcicgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAnY2hrJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAnZ29yJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMywgQlVTKSwKICAgICAgICAna3JlJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIFNVQldBWSkKICAgICksCiAgICAnc3BvJyA9PiBhcnJheSgKICAgICAgICAnY2hrJyA9PiBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAndmFzJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDcsIFNVQldBWSkKICAgICksCiAgICAndmFzJyA9PiBhcnJheSgKICAgICAgICAnc3BvJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ25vdicgPT4gY2FuR2V0KDExLCBGT09UKQogICAgKSwKICAgICdrcmUnID0+IGFycmF5KAogICAgICAgICdnb3InID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgICdsZXQnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoNywgRk9PVCkKICAgICksCiAgICAnZHZvJyA9PiBhcnJheSgKICAgICAgICAnaXNhJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdsZXQnID0+IGNhbkdldCg2LCBGT09UKQogICAgKSwKICAgICdpc2EnID0+IGFycmF5KAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnbm92JyA9PiBjYW5HZXQoNSwgRk9PVCkKICAgICksCiAgICAnbm92JyA9PiBhcnJheSgKICAgICAgICAndmFzJyA9PiBjYW5HZXQoMTEsIEZPT1QpLAogICAgICAgICdpc2EnID0+IGNhbkdldCg1LCBGT09UKSwKICAgICAgICAncmFzJyA9PiBjYW5HZXQoNywgQlVTKQogICAgKSwKICAgICdyYXMnID0+IGFycmF5KAogICAgICAgICdub3YnID0+IGNhbkdldCg3LCBCVVMpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBGT09UKQogICAgKSwKICAgICdnb3MnID0+IGFycmF5KAogICAgICAgICd2YXMnID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICdkdm8nID0+IGNhbkdldCg2LCBGT09UKSwKICAgICAgICAnZ29yJyA9PiBjYW5HZXQoNiwgU1VCV0FZKSwKICAgICAgICAnbGV0JyA9PiBjYW5HZXQoNywgRk9PVCksCiAgICAgICAgJ3ZsYScgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgJ3NlbicgPT4gYXJyYXkoCiAgICAgICAgJ3JhcycgPT4gY2FuR2V0KDMsIEZPT1QpLAogICAgICAgICdzcG8nID0+IGNhbkdldCg3LCBTVUJXQVkpLAogICAgICAgICdnb3MnID0+IGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2bGEnID0+IGNhbkdldCg0LCBTVUJXQVkpLAogICAgICAgICd2aXQnID0+IGNhbkdldCgyLCBTVUJXQVkpLAogICAgICAgICd0ZWgnID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgJ3ZsYScgPT4gYXJyYXkoCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIEZPT1QpLAogICAgICAgICd2a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