80-Bus News

  

January-March 1982, Volume 1, Issue 1











Page 49 of 55











49

N2 program

100 110 120 130 140 150 140 170 180 190 200 210 220 230 240 200 255 260 261 262 243 264 265 246 267 268 270 280 290 295 300 310 320 320 3350 340 350 359 360 379 380

390 –

400 410 420 430 440 450 460 470 480 499 500 510 520 a0 339 340 aa 560

REM ** The TOWERS of HANOI **

REM * by John Waddell +*

REM

CLS:GOSUB 950

SCREEN 2,2:PRINT "S discs, all different Ms PRINT “in size, are placed in"

PRINT “order on a fixed peg, with the “3 PRINT “largest at the":PRINT "bottom. “ys PRINT "There are 2 empty pegs in line with" PRINT “the first, and the task to be "ys PRINT “accomplished is":PRINT"“to transfer"; PRINT " all the discs to peg 3 so that at" PRINT "no time is a larger disc resting "; PRINT “on a smaller.":PRINT:PRINT

REM +*4* Set up pegs and discs %*x*

INPUT "When ready, press ENTER. Ready"; At CLEAR S500

CLS:DIM D(5),D$(S),P(3)sGOSUB 950

REM * Array D for discs, P for pegs * C$=CHRS (128) :ES=C$+C8

SPs= ” cid : BSs= “a at

FOR I= 1705

SP$=LEFT# (SP$, LEN (SP$)—1)

CH=C#+ES

DS (1) =SGP$+C$+SP$

NEXT

FOR IT = 1 TO 5:Dc1)=1:NEXT

P01) =5:P (2)=0:P(3)=0

FOR I = 0 TO 2:SCREEN 6+14*1,2

PRINT "Pegs I+1i:NEXT

SCREEN 1,10:FOR I = 1 TO 47

PRINT CHRS (129) ::NEXT:PRINT

FOR Y = 8 TO 26

SET (14, Y) SET (44, Y) : SET (78, Y)

SET (15, Y) :SET (47, Y) : SET (79, Y) :NEXT

FOR A = 9 TO 5S STEP -1:SCREEN 2,A

PRINT D#(A-4) =NEXT

REM * Main loop – to get moves * I=0 I=I+1:SCREEN 1,13:PRINT SPC (40)

PRINT: SCREEN 1,12:PRINT SPC (45)

PRINT: SCREEN 1, 12:PRINT "Move"sI,

INPUT “From peg"; 0%:0=VAL (Q$)

IF @=1 OR @=2 OR O=3 THEN 430

PRINT"Be sensible! "sGOTO 380 Hi=P(@):IF Hil > O THEN 440

PRINT “There is na disc on peg";@;"." GOTO 380

PRINT: SCREEN 32,12

INPUT "To peg";R$:R=VAL (RS)

IF R=1 OR R=2 OR R=3 THEN 510

PRINT “That is not possible. " SCREEN 30,12:PRINT SPC(15):GOTO 460

IF R<>Q THEN 540

PRINT "That means stay as you are!"

GOTO 440

REM * Check whether to permitted peq * H2=P(R):FOR K = 1 70 5

IF D(kK)=Q THEN 570

NEXT


This is an OCR’d version of the scanned page and likely contains recognition errors.











Page 49 of 55