first commit

This commit is contained in:
douboer
2025-09-17 16:08:16 +08:00
parent 9395faa6b2
commit 3ff47c11d5
1318 changed files with 117477 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
###
### check_move
###
## Chapter 1 section 3
@position = (' ', ('A') x 3); # Disks are all initially on peg A
sub check_move {
my $i;
my ($disk, $start, $end) = @_;
if ($disk < 1 || $disk > $#position) {
die "Bad disk number $disk. Should be 1..$#position.\n";
}
unless ($position[$disk] eq $start) {
die "Tried to move disk $disk from $start, but it is on peg $position[$disk].\n";
}
for $i (1 .. $disk-1) {
if ($position[$i] eq $start) {
die "Can't move disk $disk from $start because $i is on top of it.\n";
} elsif ($position[$i] eq $end) {
die "Can't move disk $disk to $end because $i is already there.\n";
}
}
print "Moving disk $disk from $start to $end.\n";
$position[$disk] = $end;
}