#!/usr/bin/perl

print "This recursive routine prints the Tower of Hanoi solution for n disks.\n";
print "The three pegs are A, B, C: the disks go from A to C\n";
print "Enter n: "; $n = <STDIN>; chomp($n);

$a = "A"; $b = "B"; $c = "C";
hanoi($n, $a, $b, $c);

sub hanoi {
  my($n, $a, $b, $c) = @_;
  if($n == 1) {
    print "$a -> $c\n";
  } else {
    hanoi($n - 1, $a, $c, $b);
    print "$a -> $c\n";
    hanoi($n - 1, $b, $a, $c);
  }
}
