Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Php Solve the towers of hanoi problem

function hanoi($n, $from, $to, $aux) {
  if ($n == 1) {
    echo "Move disk 1 from rod $from to rod $to\n";
  hanoi($n-1, $from, $aux, $to);
  echo "Move disk $n from rod $from to rod $to\n";
  hanoi($n-1, $aux, $to, $from);

hanoi(3, 'A', 'C', 'B');

Enter fullscreen mode Exit fullscreen mode

Top comments (0)