mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2024-12-28 01:29:49 +00:00
24 lines
468 B
ObjectPascal
24 lines
468 B
ObjectPascal
|
program TowersOfHanoi (input, output);
|
||
|
|
||
|
var
|
||
|
disks: Integer;
|
||
|
|
||
|
procedure Hanoi (source, temp, destination: char; n: integer);
|
||
|
|
||
|
begin
|
||
|
if n > 0 then
|
||
|
begin
|
||
|
Hanoi(source, destination, temp, n - 1);
|
||
|
Writeln('Move disk ', n : 1, ' from peg ', source, ' to peg ', destination);
|
||
|
Hanoi(temp, source, destination, n - 1);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
begin
|
||
|
|
||
|
Write('Enter the number of disks: ');
|
||
|
Readln(disks);
|
||
|
Writeln('Solution:');
|
||
|
Hanoi('A', 'B', 'C', disks);
|
||
|
|
||
|
end.
|