Skip to content

Instantly share code, notes, and snippets.

@zard1989
Created December 4, 2009 12:34
Show Gist options
  • Select an option

  • Save zard1989/249000 to your computer and use it in GitHub Desktop.

Select an option

Save zard1989/249000 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use 5.010;
hanoi(3, "A", "B", "C");
sub hanoi {
my ($N, $FROM, $TO, $SPACE) = @_;
if ($N == 1) {
say "Move #$N from $FROM to $TO";
}
else {
hanoi($N-1, $FROM, $SPACE, $TO);
say "Move #$N from $FROM to $TO";
hanoi($N-1, $SPACE, $TO, $FROM);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment