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.




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program 100doors64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
.equ NBDOORS,   100
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResult:       .asciz "The door @ is open.\n"
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
stTableDoors:    .skip   8 * NBDOORS
sZoneConv:       .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                             // entry of program 
    // display first line
    ldr x3,qAdrstTableDoors       // table address
    mov x5,1             
1:
    mov x4,x5
2:                               // begin loop
    ldr x2,[x3,x4,lsl #3]        // read doors index x4
    cmp x2,#0
    cset x2,eq
    //moveq x2,#1                // if x2 = 0   1 -> x2
    //movne x2,#0                // if x2 = 1   0 -> x2
    str x2,[x3,x4,lsl #3]        // store value of doors
    add x4,x4,x5                 // increment x4 with  x5 value
    cmp x4,NBDOORS               // number of doors ?
    ble 2b                       // no -> loop
    add x5,x5,#1                 // increment the increment !!
    cmp x5,NBDOORS               // number of doors ?
    ble 1b                       // no -> loop
 
                                 // loop display state doors
    mov x4,#0              
3:
    ldr x2,[x3,x4,lsl #3]        // read state doors x4 index
    cmp x2,#0
    beq 4f
    mov x0,x4                    // open -> display message
    ldr x1,qAdrsZoneConv          // display value index
    bl conversion10              // call function
    ldr x0,qAdrsMessResult
    ldr x1,qAdrsZoneConv 
    bl strInsertAtCharInc        // insert result at first @ character
    bl affichageMess             // display message
4:
    add x4,x4,1
    cmp x4,NBDOORS
    ble 3b                       // loop
 
 
100:                             // standard end of the program 
    mov x0,0                     // return code
    mov x8,EXIT                  // request to exit program
    svc 0                        // perform the system call
 
qAdrstTableDoors:        .quad stTableDoors
qAdrsMessResult:         .quad sMessResult
qAdrsZoneConv:           .quad sZoneConv
/***********************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 