user
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.

Why doesn't syntax highlighting work on this page ?

Currently, there is a limit on how many <syntaxhighlight> tags can appear on a page, so only the first few languages get highlighting, the rest are shown in monochrome.  
You could try "manual highlighting", possibly using one of the highlighters on Syntax highlighting using Mediawiki formatting or something similar.
assistant
(formerly Perl 6)

### unoptimized

**Works with**: Rakudo version 2015.09"

```
my @doors = False xx 101;
 
(.=not for @doors[0, $_ ... 100]) for 1..100;
 
say "Door $_ is ", <closed open>[ @doors[$_] ] for 1..100;
```

### optimized

```
say "Door $_ is open" for map {$^n ** 2}, 1..10;
```

### probably the most compact idiom

```
say 'Door $_ is open' for (1..10)»²;
```

### Here's a version using the cross meta-operator instead of a map:

```
 say "Door $_ is open" for 1..10 X** 2;
```

This one prints both opened and closed doors:

```
say "Door $_ is ", <closed open>[.sqrt == .sqrt.floor] for 1..100;
```

### verbose version, but uses ordinary components

**Works with**: Rakudo version 2016.07 Tom Legrady

```
sub  output( @arr, $max ) {
    my $output = 1;
    for 1..^$max -> $index {
	if @arr[$index] {
	    printf "%4d", $index;
	    say '' if $output++ %%  10;
	}
    }
    say '';
}

sub MAIN ( Int :$doors = 100 ) {
    my $doorcount = $doors + 1;
    my @door[$doorcount] = 0 xx ($doorcount);
    
    INDEX:
    for 1...^$doorcount -> $index {
        # flip door $index & its multiples, up to last door.
        #
	for ($index, * + $index ... *)[^$doors] -> $multiple {
	    next INDEX if $multiple > $doors;
	    @door[$multiple] =  @door[$multiple] ?? 0 !! 1;
	}
    }
    output @door, $doors+1;
}
```

Output:

```
$ ./100_doors.pl6 -doors=100
   1   4   9  16  25  36  49  64  81

```