Files
gw-basic-2026/tests/programs/hundred_doors.bas
Eremey Valetov 691031a7f9 Fix RESTORE with line number, add 8 Rosetta Code test programs
RESTORE n now correctly positions past the DATA token so the next
READ gets actual values instead of the token byte.

New tests: Roman numerals, Luhn validator, Towers of Hanoi, 100 Doors,
Pascal's triangle, type declarations, Hailstone sequence, multiplication
table.  50 tests now pass.
2026-02-15 16:22:55 -05:00

18 lines
509 B
QBasic

10 REM 100 Doors problem - Rosetta Code
20 DIM D(100)
30 FOR PASS = 1 TO 100
40 FOR DOOR = PASS TO 100 STEP PASS
50 D(DOOR) = 1 - D(DOOR)
60 NEXT DOOR
70 NEXT PASS
80 REM Only perfect squares should be open
90 C = 0
100 FOR I = 1 TO 100
110 IF D(I) = 0 THEN 150
120 S = SQR(I)
130 IF INT(S) <> S THEN PRINT "FAIL: door"; I; "open but not perfect square" : END
140 C = C + 1
150 NEXT I
160 IF C <> 10 THEN PRINT "FAIL: expected 10 open doors, got"; C : END
170 PRINT "100 Doors OK:"; C; "open"