fork(2) download
  1. <?php
  2. define('SUBWAY', 'sub');
  3. define('FOOT', 'foot');
  4. define('BUS', 'bus');
  5.  
  6. $transportName = array(
  7. SUBWAY => 'едешь на метро',
  8. FOOT => 'идешь пешком',
  9. BUS => 'едешь на автобусе'
  10. );
  11.  
  12. $pointNames = array(
  13. 'pet' => 'ст. м. Петроградская',
  14. 'chk' => 'ст. м. Чкаловская',
  15. 'gor' => 'ст. м. Горьковская',
  16. 'spo' => 'ст. м. Спортивная',
  17. 'vas' => 'ст. м. Василеостровская',
  18. 'kre' => 'Петропавловская крепость',
  19. 'let' => 'Летний сад',
  20. 'dvo' => 'Дворцовая площадь',
  21. 'isa' => 'Исакиевский собор',
  22. 'nov' => 'Новая Голландия',
  23. 'ras' => 'Дом Раскольникова',
  24. 'gos' => 'Гостиный Двор',
  25. 'sen' => 'Сенная Площадь',
  26. 'vla' => 'ст. м. Владимирская',
  27. 'vit' => 'Витебский вокзал',
  28. 'teh' => 'Технологический Институт'
  29. );
  30.  
  31. $paths = array(
  32. 'pet' => array(
  33. 'chk' => canGet(10, BUS),
  34. 'gor' => canGet(3, SUBWAY)
  35. ),
  36.  
  37. 'chk' => array(
  38. 'pet' => canGet(10, BUS),
  39. 'spo' => canGet(3, SUBWAY)
  40. ),
  41.  
  42. 'gor' => array(
  43. 'pet' => canGet(3, BUS),
  44. 'kre' => canGet(5, FOOT),
  45. 'gos' => canGet(6, SUBWAY)
  46. ),
  47.  
  48. 'spo' => array(
  49. 'chk' => canGet(3, SUBWAY),
  50. 'vas' => canGet(10, BUS),
  51. 'sen' => canGet(7, SUBWAY)
  52. ),
  53.  
  54. 'vas' => array(
  55. 'spo' => canGet(10, BUS),
  56. 'gos' => canGet(7, SUBWAY),
  57. 'nov' => canGet(11, FOOT)
  58. ),
  59.  
  60. 'kre' => array(
  61. 'gor' => canGet(5, FOOT)
  62. ),
  63.  
  64. 'let' => array(
  65. 'dvo' => canGet(6, FOOT),
  66. 'gos' => canGet(7, FOOT)
  67. ),
  68.  
  69. 'dvo' => array(
  70. 'isa' => canGet(6, FOOT),
  71. 'gos' => canGet(6, FOOT),
  72. 'let' => canGet(6, FOOT)
  73. ),
  74.  
  75. 'isa' => array(
  76. 'dvo' => canGet(6, FOOT),
  77. 'nov' => canGet(5, FOOT)
  78. ),
  79.  
  80. 'nov' => array(
  81. 'vas' => canGet(11, FOOT),
  82. 'isa' => canGet(5, FOOT),
  83. 'ras' => canGet(7, BUS)
  84. ),
  85.  
  86. 'ras' => array(
  87. 'nov' => canGet(7, BUS),
  88. 'sen' => canGet(3, FOOT)
  89. ),
  90.  
  91. 'gos' => array(
  92. 'vas' => canGet(7, SUBWAY),
  93. 'sen' => canGet(3, SUBWAY),
  94. 'dvo' => canGet(6, FOOT),
  95. 'gor' => canGet(6, SUBWAY),
  96. 'let' => canGet(7, FOOT),
  97. 'vla' => canGet(7, FOOT)
  98. ),
  99.  
  100. 'sen' => array(
  101. 'ras' => canGet(3, FOOT),
  102. 'spo' => canGet(7, SUBWAY),
  103. 'gos' => canGet(3, SUBWAY),
  104. 'vla' => canGet(4, SUBWAY),
  105. 'vit' => canGet(2, SUBWAY),
  106. 'teh' => canGet(3, SUBWAY)
  107. ),
  108.  
  109. 'vla' => array(
  110. 'sen' => canGet(4, SUBWAY),
  111. 'gos' => canGet(7, FOOT),
  112. 'vit' => canGet(3, SUBWAY)
  113. ),
  114.  
  115. 'vit' => array(
  116. 'sen' => canGet(2, SUBWAY),
  117. 'teh' => canGet(2, SUBWAY),
  118. 'vla' => canGet(3, SUBWAY)
  119. ),
  120.  
  121. 'teh' => array(
  122. 'sen' => canGet(3, SUBWAY),
  123. 'vit' => canGet(2, SUBWAY)
  124. )
  125. );
  126.  
  127. function canGet($time, $byWhat) {
  128. return array('time' => $time, 'by' => $byWhat);
  129. }
  130.  
  131. $pathDone = [];
  132.  
  133. function makeStep($paths, $pathDone, $time, $point, $target) {
  134. $pathDone[] = $point;
  135. //echo "мы на - $point -\n";
  136. //echo "пройденный путь :";
  137.  
  138.  
  139. //echo "\n";
  140.  
  141. //echo "общее время $time \n";
  142.  
  143. if ($point == $target) {
  144. echo "путь пройден за $time\n";
  145. echo "путь - ";
  146. foreach ($pathDone as $names) {
  147. echo " $names";
  148. }
  149. echo "\n";
  150. return $pathDone;
  151. }
  152.  
  153.  
  154. //echo "цели для след. шага:";
  155. foreach($paths[$point] as $name => $value) {
  156. if (!in_array($name, $pathDone)) {
  157. // echo "- $name -\n";
  158.  
  159. $time += $paths[$point][$name]['time'];
  160.  
  161. $point = $name;
  162.  
  163. makeStep($paths, $pathDone, $time, $point, $target);
  164. }
  165. }
  166. }
  167.  
  168. $a = makeStep($paths, $pathDone, 0, 'pet', 'nov');
  169.  
Success #stdin #stdout #stderr 0.02s 24448KB
stdin
Standard input is empty
stdout
путь пройден за 43
путь -  pet chk spo vas gos sen ras nov
путь пройден за 44
путь -  pet chk spo vas gos dvo isa nov
путь пройден за 50
путь -  pet chk spo vas gos let dvo isa nov
путь пройден за 47
путь -  pet chk spo vas gos vla sen ras nov
путь пройден за 51
путь -  pet chk spo vas gos vla vit sen ras nov
путь пройден за 57
путь -  pet chk spo vas gos vla vit teh sen ras nov
путь пройден за 30
путь -  pet chk spo vas nov
путь пройден за 33
путь -  pet chk spo sen ras nov
путь пройден за 44
путь -  pet chk spo sen gos vas nov
путь пройден за 44
путь -  pet chk spo sen gos dvo isa nov
путь пройден за 50
путь -  pet chk spo sen gos let dvo isa nov
путь пройден за 58
путь -  pet chk spo sen vla gos vas nov
путь пройден за 58
путь -  pet chk spo sen vla gos dvo isa nov
путь пройден за 64
путь -  pet chk spo sen vla gos let dvo isa nov
путь пройден за 63
путь -  pet chk spo sen vit vla gos vas nov
путь пройден за 63
путь -  pet chk spo sen vit vla gos dvo isa nov
путь пройден за 69
путь -  pet chk spo sen vit vla gos let dvo isa nov
путь пройден за 68
путь -  pet chk spo sen teh vit vla gos vas nov
путь пройден за 68
путь -  pet chk spo sen teh vit vla gos dvo isa nov
путь пройден за 74
путь -  pet chk spo sen teh vit vla gos let dvo isa nov
путь пройден за 45
путь -  pet gor gos vas spo sen ras nov
путь пройден за 32
путь -  pet gor gos vas nov
путь пройден за 32
путь -  pet gor gos sen ras nov
путь пройден за 39
путь -  pet gor gos sen spo vas nov
путь пройден за 33
путь -  pet gor gos dvo isa nov
путь пройден за 45
путь -  pet gor gos let dvo isa nov
путь пройден за 42
путь -  pet gor gos vla sen ras nov
путь пройден за 49
путь -  pet gor gos vla sen spo vas nov
путь пройден за 46
путь -  pet gor gos vla vit sen ras nov
путь пройден за 53
путь -  pet gor gos vla vit sen spo vas nov
путь пройден за 52
путь -  pet gor gos vla vit teh sen ras nov
путь пройден за 59
путь -  pet gor gos vla vit teh sen spo vas nov
NULL
stderr
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: dvo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gor in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vit in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: teh in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: nov in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: sen in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gos in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: dvo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gor in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: dvo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gor in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vit in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: dvo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gor in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: dvo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gor in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gor in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: gos in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: sen in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: nov in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: sen in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: spo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vas in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: dvo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: let in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vla in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: spo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vas in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vit in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: spo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vas in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: teh in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: spo in /home/B6CCJd/prog.php on line 160
PHP Notice:  Undefined index: vas in /home/B6CCJd/prog.php on line 160