There are 100 doors in a row that are all initially closed.

You make 100 passes by the doors.

The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it).

The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it.

The third time, visit every 3rd door   (door #3, #6, #9, ...), etc,   until you only visit the 100th door.



Task

Answer the question:   what state are the doors in after the last pass?   Which are open, which are closed?


Alternate:
As noted in this page's   discussion page,   the only doors that remain open are those whose numbers are perfect squares.

Opening only those doors is an   optimization   that may also be expressed;
however, as should be obvious, this defeats the intent of comparing implementations across programming languages.




 
    program
 
    map
    end
 
MAX_DOOR_NUMBER         equate(100)
CRLF                    equate('<13,10>')
 
Doors                   byte,dim(MAX_DOOR_NUMBER)
Pass                    byte
DoorNumber              byte
DisplayString           cstring(2000)
 
ResultWindow            window('Result'),at(,,133,291),center,double,auto
                            prompt('Door states:'),at(8,4),use(?PromptTitle)
                            text,at(8,16,116,266),use(DisplayString),boxed,vscroll,font('Courier New',,,,CHARSET:ANSI),readonly
                        end
 
    code
 
    Doors :=: false
    loop Pass = 1 to MAX_DOOR_NUMBER
        loop DoorNumber = Pass to MAX_DOOR_NUMBER by Pass
            Doors[DoorNumber] = choose(Doors[DoorNumber], false, true)
        end
    end
 
    clear(DisplayString)
    loop DoorNumber = 1 to MAX_DOOR_NUMBER
        DisplayString = DisplayString & format(DoorNumber, @n3) & ' is ' & choose(Doors[DoorNumber], 'opened', 'closed') & CRLF
    end
    open(ResultWindow)
    accept
    end
    close(ResultWindow)
 
    return
 