init: repo
This commit is contained in:
30
open_set/47_hanoi.pas
Normal file
30
open_set/47_hanoi.pas
Normal file
@@ -0,0 +1,30 @@
|
||||
program Hanoi;
|
||||
const split = ',';
|
||||
var
|
||||
n, t, i: integer;
|
||||
|
||||
procedure move(x, y: integer);
|
||||
begin
|
||||
write(x,y,split);
|
||||
end;
|
||||
|
||||
procedure hanoi(n, one, two, three: integer);
|
||||
begin
|
||||
if n = 1 then
|
||||
move(one, three)
|
||||
else
|
||||
begin
|
||||
hanoi(n - 1, one, three, two);
|
||||
move(one, three);
|
||||
hanoi(n - 1, two, one, three);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
read(n);
|
||||
for i := 1 to n do
|
||||
begin
|
||||
read(t);
|
||||
hanoi(t, 1, 2, 3);
|
||||
end;
|
||||
end.
|
||||
Reference in New Issue
Block a user