Skip to content

Instantly share code, notes, and snippets.

@pascaldevink
Created November 20, 2009 10:33
Show Gist options
  • Save pascaldevink/239406 to your computer and use it in GitHub Desktop.
Save pascaldevink/239406 to your computer and use it in GitHub Desktop.
<?php
function hanoi($plates, $from, $to) {
while($plates > 0) {
$using = 6 - ($from + $to);
hanoi(--$plates, $from, $using);
print "Move plate from $from to $to".PHP_EOL;
$from = $using;
}
}
//Arguments: No of plates, From stick(1,2 or 3),
// To stick(1,2 or 3; except From stick)
hanoi(5, 1, 3);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment