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.




 
entry LP_DO_IT
 
    variables
        string  V_DOORS
        boolean V_DOOR_STATE
        string  V_DOOR_STATE_S
        numeric V_IDX
        numeric V_TOTAL_DOORS
        string  V_DOOR_STATE_LIST
        numeric V_LOOP_COUNT
    endvariables
 
    V_TOTAL_DOORS = 100
    putitem V_DOORS, V_TOTAL_DOORS, 0
 
    V_DOORS = $replace (V_DOORS, 1, "·;", "·;0", -1)
 
    putitem/id V_DOOR_STATE_LIST, "1", "Open"
    putitem/id V_DOOR_STATE_LIST, "0", "Close"
 
    V_LOOP_COUNT = 1
    while (V_LOOP_COUNT <= V_TOTAL_DOORS)
        V_IDX = 0
        V_IDX = V_IDX + V_LOOP_COUNT
 
        getitem V_DOOR_STATE, V_DOORS, V_IDX
        while (V_IDX <= V_TOTAL_DOORS)
 
            V_DOOR_STATE = !V_DOOR_STATE
            getitem/id V_DOOR_STATE_S, V_DOOR_STATE_LIST, $number(V_DOOR_STATE)
            putitem V_DOORS, V_IDX, V_DOOR_STATE
 
            V_IDX = V_IDX + V_LOOP_COUNT
            getitem V_DOOR_STATE, V_DOORS, V_IDX
        endwhile
 
        V_LOOP_COUNT = V_LOOP_COUNT + 1
 
    endwhile
 
    V_IDX = 1
    getitem V_DOOR_STATE, V_DOORS, V_IDX
    while (V_IDX <= V_TOTAL_DOORS)
        getitem/id V_DOOR_STATE_S, V_DOOR_STATE_LIST, $number(V_DOOR_STATE)
        if (V_DOOR_STATE)
            putmess "Door %%V_IDX%%% is finally %%V_DOOR_STATE_S%%%"
        endif
 
        V_IDX = V_IDX + 1
        getitem V_DOOR_STATE, V_DOORS, V_IDX
    endwhile
 
end ; LP_DO_IT
 
 