Skip to content

Instantly share code, notes, and snippets.

@AlexDaniel
Last active September 19, 2017 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDaniel/c31400216809502871b082ad79b67428 to your computer and use it in GitHub Desktop.
Save AlexDaniel/c31400216809502871b082ad79b67428 to your computer and use it in GitHub Desktop.
use nqp;
sub hanoi(int $n, $a = 'A', $b = 'B', $c = 'C') {
nqp::if(nqp::isgt_i($n, 0),
nqp::stmts(
(hanoi nqp::sub_i($n, 1), $a, $c, $b),
(nqp::say("Move disk $n from peg $a to peg $c")),
(hanoi nqp::sub_i($n, 1), $b, $a, $c)))
}
hanoi(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment