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.




100H: /* FIND THE FIRST FEW SQUARES VIA THE UNOPTIMISED DOOR FLIPPING METHOD */
 
    /* BDOS SYSTEM CALL */
    BDOS: PROCEDURE( FN, ARG );
        DECLARE FN BYTE, ARG ADDRESS;
        GO TO 5;
    END BDOS;
 
    /* PRINTS A BYTE AS A CHARACTER */
    PRINT$CHAR: PROCEDURE( CH );
        DECLARE CH BYTE;
        CALL BDOS( 2, CH );
    END PRINT$CHAR;
 
    /* PRINTS A BYTE AS A NUMBER */
    PRINT$BYTE: PROCEDURE( N );
        DECLARE N BYTE;
        DECLARE ( V, D3, D2 ) BYTE;
        V  = N;
        D3 = V MOD 10;
        IF ( V := V / 10 ) <> 0 THEN DO;
            D2 = V MOD 10;
            IF ( V := V / 10 ) <> 0 THEN CALL PRINT$CHAR( '0' + V );
            CALL PRINT$CHAR( '0' + D2 );
        END;
        CALL PRINT$CHAR( '0' + D3 );
    END PRINT$BYTE;
 
    DECLARE DOOR$DCL LITERALLY '101';
    DECLARE FALSE    LITERALLY '0';
    DECLARE CR       LITERALLY '0DH';
    DECLARE LF       LITERALLY '0AH';
 
    /* ARRAY OF DOORS - DOOR( I ) IS TRUE IF OPEN, FALSE IF CLOSED */
    DECLARE DOOR( DOOR$DCL ) BYTE;
    DECLARE ( I, J )         BYTE;
 
    /* SET ALL DOORS TO CLOSED */
    DO I = 0 TO LAST( DOOR ); DOOR( I ) = FALSE; END;
    /* REPEATEDLY FLIP THE DOORS */
    DO I = 1 TO LAST( DOOR );
       DO J = I TO LAST( DOOR ) BY I;
          DOOR( J ) = NOT DOOR( J );
       END;
    END;
    /* DISPLAY THE RESULTS */
    DO I = 1 TO LAST( DOOR );
       IF DOOR( I ) THEN DO;
          CALL PRINT$CHAR( ' ' );
          CALL PRINT$BYTE( I );
       END;
    END;
    CALL PRINT$CHAR( CR );
    CALL PRINT$CHAR( LF );
EOF
 