Perl 脚本之2:汉诺塔相关脚本
#!/usr/bin/perl#author: peipei
#date:2014_06_06
sub hanoi{
my ($n,$start,$end,$extra)=@_;
if ($n == 1){
print "Move disk #1 form $start to $end. \n ";
} else {
hanoi($n-1,$start,$extra,$end);
print "Move disk #$n from $start to $extra. \n";
hanoi($n-1,$extra,$end,$start);
}
}
hanoi(5,A,B,C);
页:
[1]