BEGIN
COMMENT  THIS PROGRAM PRINTS THE MOVES REQUIRED TO TRANSFER A TOWER OF 
         ANY HEIGHT FROM NEEDLE 1 TO NEEDLE 3.;

STRING TEST;
INTEGER TOTAL;
PROCEDURE MOVETOWER(HEIGHT,FROMNEEDLE,TONEEDLE,USINGNEEDLE);
  INTEGER HEIGHT,FROMNEEDLE,TONEEDLE,USINGNEEDLE;
  BEGIN
    PROCEDURE MOVEDISK(TAKEOFF,PUTON);
      INTEGER TAKEOFF,PUTON;
      BEGIN
        WRITE(TAKEOFF,"   ->",PUTON);
      END;

    IF HEIGHT>0 THEN
      BEGIN
        MOVETOWER(HEIGHT-1,FROMNEEDLE,USINGNEEDLE,TONEEDLE);
        MOVEDISK(FROMNEEDLE,TONEEDLE);
        MOVETOWER(HEIGHT-1,USINGNEEDLE,TONEEDLE,FROMNEEDLE);
      END;
  END;%MOVETOWER%

BEGIN%HANOI%
   WRITE("THIS PROGRAM WILL PRINT THE MOVES REQUIRED");
   WRITE("TO MOVE A TOWER OF RINGS FROM ONE NEEDLE TO");
   WRITE("ANOTHER.  THERE ARE THREE NEEDLES AND THE RULES");
   WRITE("ARE THAT YOU CAN NEVER MOVE A LARGER RING ON TOP");
   WRITE("OF A SMALLER RING.");
   TEST:="YES";
  WHILE TEST="YES" DO BEGIN
   WRITE("INPUT THE NUMBER OF RINGS");
   READ(TOTAL);
   WRITE("FROM TOWER -> TO TOWER");
   MOVETOWER(TOTAL,1,3,2);
   WRITE("ANOTHER VALUE? ENTER YES OR NO");
   READ(TEST);
 END;
END;
END
