RosettaCodeData/Task/100-doors/CBASIC/100-doors.basic
2024-10-16 18:07:41 -07:00

27 lines
509 B
Text

dim doors%(100)
print "Finding solution to the 100 Doors Problem"
rem - all doors are initially closed
for i% = 1 to 100
doors%(i%) = 0
next i%
rem - pass through at increasing intervals
for i% = 1 to 100
for j% = i% to 100 step i%
rem - flip each door encountered
doors%(j%) = 1 - doors%(j%)
next j%
next i%
rem - show which doors are open
print "The open doors are: ";
for i% = 1 to 100
if doors%(i%) = 1 then print i%;
next i%
print
print "Thanks for consulting the puzzle guru!"
end