100 REM THIS PROGRAM PLAYS BATNUM
110 '
120 LET N = 20 + INT(80*RND)
130 LET K = 5 + INT(10*RND)
140 PRINT "LEGAL MOVES ARE:"
150 PRINT "TAKE AWAY 1 THROUGH "K
160 PRINT "LAST PERSON TO MOVE LOOSES."
170 PRINT
180 PRINT "THE INITIAL NUMBER IS"N
190 PRINT
200 '
210 REM OPPONANTS MOVE,
220 PRINT "YOUR MOVE ";
230 INPUT X
240 IF X > K THEN 270
250 IF X < 1 THEN 270
260 IF X <= N THEN 310
270 PRINT "ILLEGAL MOVE."
280 PRINT
290 GOTO 220
300 '
310 REM TEST FOR WIN.
320 LET N = N - X
330 IF N > 0 THEN 410
340 PRINT "I WIN***"
350 PRINT
360 PRINT
370 PRINT "NEW GAME."
380 PRINT
390 GOTO 120
400 '
410 REM MACHINE'S MOVE
420 LET Q = INT ((N-1)/(K+1))
430 LET Y = N - 1 - Q*(K+1)
440 IF Y = 0 THEN 530
450 LET N = N - Y
460 PRINT "MY MOVE IS "Y
470 PRINT
480 IF N = 0 THEN 600
490 PRINT "NEW TOTAL IS "N
500 PRINT
510 GOTO 210
520 '
530 REM MAKE RANDOM MOVE
540 IF N > 1 THEN 570
550 LET Y = 1
560 GOTO 450
570 LET Y = 1 + INT(K*RND)
580 GOTO 450
590 '
600 REM MACHINE LOST.
610 PRINT "YOU WIN***"
620 GOTO 350
630 END