Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { paulogp }
- { mac os 7 }
- program Ada22p;
- uses
- MemTypes, QuickDraw, OSIntf;
- const
- MAX = 5;
- var
- n: integer;
- fim: string;
- function torres(n: integer; origem, auxiliar, destino: char): integer;
- begin
- if n = 1 then writeln('T1: Peça ', n, ' de ', origem, ' para ', destino);
- if n > 1 then
- begin
- torres:= torres(n - 1, origem, destino, auxiliar);
- writeln('T2: Peça ', n, ' de ', origem, ' para ', destino);
- torres:= torres(n - 1, auxiliar, origem, destino);
- end;
- if (n mod 3) = 0 then
- begin
- writeln;
- write('Pausa');
- writeln;
- readln;
- end;
- end;
- begin
- repeat
- clearscreen;
- gotoxy(33, 2);
- writeln('Torres de Hanoi');
- gotoxy(33, 3);
- writeln('~~~~~~~~~~~~~~~');
- gotoxy(36, 4);
- writeln('Paulo G.P.');
- writeln;
- repeat
- write('Número de anéis [ 1; ', MAX, ']: ');
- readln(n);
- writeln;
- if (n < 1) or (n > MAX) then writeln('Atenção!');
- until (n >= 1) and (n <= MAX);
- clearscreen;
- gotoxy(38, 1);
- writeln('Tabela');
- gotoxy(38, 2);
- writeln('~~~~~~');
- writeln;
- writeln(torres(n, 'A', 'B', 'C'));
- writeln;
- writeln('fim do movimento.');
- writeln;
- writeln;
- write('Repetir (s/n): ');
- readln(fim);
- uprstring(fim, true);
- until fim = 'N';
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement