CanonSharp/OpenSet/47_hanoi.pas
jackfiled 89ce313b77 feat: CanonSharp Benchmark. (#4)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/4
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-19 14:37:34 +08:00

31 lines
469 B
ObjectPascal

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.