Advertisement
paulogp

Torres de Hanoi

Aug 7th, 2011
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.25 KB | None | 0 0
  1. { paulogp }
  2. { mac os 7 }
  3. program Ada22p;
  4.  
  5. uses
  6.     MemTypes, QuickDraw, OSIntf;
  7.  
  8. const
  9.     MAX = 5;
  10.  
  11. var
  12.     n: integer;
  13.     fim: string;
  14.  
  15.  
  16. function torres(n: integer; origem, auxiliar, destino: char): integer;
  17. begin
  18.     if n = 1 then writeln('T1: Peça ', n, ' de ', origem, ' para ', destino);
  19.     if n > 1 then
  20.     begin
  21.         torres:= torres(n - 1, origem, destino, auxiliar);
  22.         writeln('T2: Peça ', n, ' de ', origem, ' para ', destino);
  23.         torres:= torres(n - 1, auxiliar, origem, destino);
  24.     end;
  25.     if (n mod 3) = 0 then
  26.     begin
  27.         writeln;
  28.         write('Pausa');
  29.         writeln;
  30.         readln;
  31.     end;
  32. end;
  33.  
  34. begin
  35.     repeat
  36.         clearscreen;
  37.         gotoxy(33, 2);
  38.         writeln('Torres de Hanoi');
  39.         gotoxy(33, 3);
  40.         writeln('~~~~~~~~~~~~~~~');
  41.         gotoxy(36, 4);
  42.         writeln('Paulo G.P.');
  43.         writeln;
  44.         repeat
  45.             write('Número de anéis [ 1; ', MAX, ']: ');
  46.             readln(n);
  47.             writeln;
  48.             if (n < 1) or (n > MAX) then writeln('Atenção!');
  49.         until (n >= 1) and (n <= MAX);
  50.         clearscreen;
  51.         gotoxy(38, 1);
  52.         writeln('Tabela');
  53.         gotoxy(38, 2);
  54.         writeln('~~~~~~');
  55.         writeln;
  56.         writeln(torres(n, 'A', 'B', 'C'));
  57.         writeln;
  58.         writeln('fim do movimento.');
  59.         writeln;
  60.         writeln;
  61.         write('Repetir (s/n): ');
  62.         readln(fim);
  63.         uprstring(fim, true);
  64.     until fim = 'N';
  65. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement