sub factorial
{
factorial
my ($n) = @_;
return 1 if $n == 0;
return factorial($n-1) * $n;
}
##```
##
sub hanoi
{
my ($n, $start, $end, $extra) = @_;
if ($n == 1)
{
print "Move disk #1 from $start to $end.\n";
}
else
{
hanoi($n-1, $start, $extra, $end);
print "Move disk #$n from $start to $end.\n";
hanoi($n-1, $extra, $end, $start);
}
}
##
```

```
##
Move disk #1 from A to C.
Move disk #2 from A to B.
Move disk #1 from C to B.
Move disk #3 from A to C.
Move disk #1 from B to A.
Move disk #2 from B to C.
Move disk #1 from A to C.
```