function hanoi($topN, $from, $to, $inter) { if ($topN != 0) { hanoi($topN - 1, $from, $inter, $to); //echo "Moving Disk $topN from $from to $to \n"; hanoi($topN - 1, $inter, $to, $from); } }
function hanoi($n, $a, $b, $c) { if ($n > 0) { hanoi($n - 1, $a, $c, $b); echo $n . '番目の円盤を' . $a . 'から' . $b . 'に移動する'; echo '<br>'; hanoi($n - 1, $c, $b, $a); } }
/** * @ProfileGroup("cat1", "cat2") */ function hanoi($plates, $from, $to) { while ($plates > 0) { $using = 6 - ($from + $to); hanoi(--$plates, $from, $using); //print "Move plate from $from to $to<br>"; $from = $using; } }
function hanoi($n, $from, $transfrom, $to, &$path) { if ($n == 1) { move(1, $from, $to, $path); } else { hanoi($n - 1, $from, $to, $transfrom, $path); move($n, $from, $to, $path); hanoi($n - 1, $transfrom, $from, $to, $path); } }
function hanoi($n, $a, $b, $c) { global $step; if ($n == 1) { $step++; echo "将圆盘 {$n} 从 {$a} 柱子 到 {$c} 柱子" . PHP_EOL; } else { hanoi($n - 1, $a, $c, $b); $step++; echo "将圆盘 {$n} 从 {$a} 柱子 到 {$c} 柱子" . PHP_EOL; hanoi($n - 1, $b, $a, $c); } }
function hanoi(int $count, array &$from, array &$to, array &$support) { if ($count === 0) { return; } if ($count === 1) { array_push($to, array_pop($from)); return; } hanoi($count - 1, $from, $support, $to); array_push($to, array_pop($from)); hanoi($count - 1, $support, $to, $from); }