100 doors: Difference between revisions

6,714 bytes added ,  18 days ago
m
imported>Grootson
 
(46 intermediate revisions by 23 users not shown)
Line 594:
NEXT list = VALUE #( BASE list ( i * i ) ) ) ).
</syntaxhighlight>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO INITIALIZE:
SHARE doors
PUT {} IN doors
FOR door IN {1..100}:
PUT 0 IN doors[door]
 
HOW TO TOGGLE door:
SHARE doors
PUT 1-doors[door] IN doors[door]
 
HOW TO WALK step:
SHARE doors
PUT step IN door
WHILE door <= 100:
TOGGLE door
PUT door+step IN door
 
HOW TO DISPLAY OPEN DOORS:
SHARE doors
FOR door IN {1..100}:
IF doors[door] = 1:
WRITE "Door", door, "is open"/
 
INITIALIZE
FOR pass IN {1..100}: WALK pass
DISPLAY OPEN DOORS</syntaxhighlight>
{{out}}
<pre>Door 1 is open
Door 4 is open
Door 9 is open
Door 16 is open
Door 25 is open
Door 36 is open
Door 49 is open
Door 64 is open
Door 81 is open
Door 100 is open</pre>
 
=={{header|ACL2}}==
Line 905 ⟶ 944:
=={{header|ALGOL 60}}==
{{works with|A60}}
'''begin'''
<syntaxhighlight lang="algol60">
begin
''comment - 100 doors problem in ALGOL-60;''
'''boolean''' '''array''' doors[1:100];
'''integer''' i, j;
'''boolean''' open, closed;
open := '''true''';
closed := '''not''' '''true''';
outstring(1,"100 Doors Problem\n");
''comment - all doors are initially closed;''
'''for''' i := 1 '''step''' 1 '''until''' 100 '''do'''
doors[i] := closed;
''comment''
'' cycle through at increasing intervals''
'' and flip each door encountered;''
'''for''' i := 1 '''step''' 1 '''until''' 100 '''do'''
'''for''' j := i '''step''' i '''until''' 100 '''do'''
doors[j] := '''not''' doors[j];
''comment - show which doors are open;''
outstring(1,"The open doors are:");
'''for''' i := 1 '''step''' 1 '''until''' 100 '''do'''
'''if''' doors[i] '''then'''
outinteger(1,i);
'''end'''
 
comment - 100 doors problem in ALGOL-60;
 
boolean array doors[1:100];
integer i, j;
boolean open, closed;
 
open := true;
closed := not true;
 
outstring(1,"100 Doors Problem\n");
 
comment - all doors are initially closed;
for i := 1 step 1 until 100 do
doors[i] := closed;
 
comment
cycle through at increasing intervals
and flip each door encountered;
for i := 1 step 1 until 100 do
for j := i step i until 100 do
doors[j] := not doors[j];
 
comment - show which doors are open;
outstring(1,"The open doors are:");
for i := 1 step 1 until 100 do
if doors[i] then
outinteger(1,i);
 
end
</syntaxhighlight>
{{out}}
<pre>
Line 946 ⟶ 984:
=={{header|ALGOL 68}}==
'''unoptimized'''
<syntaxhighlight lang="algol68"># declare some constants #
INT limit = 100;
 
'''PROC''' doors = ('''INT''' limit)'''VOID''':
(
'''MODE''' '''DOORSTATE''' = '''BOOL''';
'''BOOL''' closed = '''FALSE''';
'''BOOL''' open = '''NOT''' closed;
'''MODE''' '''DOORLIST''' = [limit]'''DOORSTATE''';
'''DOORLIST''' the doors;
'''FOR''' i '''FROM''' '''LWB''' the doors '''TO''' '''UPB''' the doors '''DO''' the doors[i]:=closed '''OD''';
'''FOR''' i '''FROM''' '''LWB''' the doors '''TO''' '''UPB''' the doors '''DO'''
'''FOR''' j '''FROM''' '''LWB''' the doors '''BY''' i '''TO''' '''UPB''' the doors '''DO'''
the doors[j] := '''NOT''' the doors[j]
'''OD'''
'''OD''';
'''FOR''' i '''FROM''' '''LWB''' the doors '''TO''' '''UPB''' the doors '''DO'''
print((whole(i,-12)," is ",(the doors[i]|"opened"|"closed"),newline))
'''OD'''
);
doors(100)
 
DOORLIST the doors;
FOR i FROM LWB the doors TO UPB the doors DO the doors[i]:=closed OD;
 
FOR i FROM LWB the doors TO UPB the doors DO
FOR j FROM LWB the doors TO UPB the doors DO
IF j MOD i = 0 THEN
the doors[j] := NOT the doors[j]
FI
OD
OD;
FOR i FROM LWB the doors TO UPB the doors DO
printf(($g" is "gl$,i,(the doors[i]|"opened"|"closed")))
OD
);
doors;</syntaxhighlight>
'''optimized'''
 
<syntaxhighlight lang="algol68">PROC doors optimised = ( INT limit )VOID:
'''PROC''' doors optimised = ( '''INT''' limit )'''VOID''':
FOR i TO limit DO
'''FOR''' i '''TO''' limit '''DO'''
REAL num := sqrt(i);
'''REAL''' num := sqrt(i);
printf(($g" is "gl$,i,(ENTIER num = num |"opened"|"closed") ))
print((whole(i,0)," is ",('''ENTIER''' num = num |"opened"|"closed"),newline))
OD
'''OD'''
;
;
doors optimised(limit)</syntaxhighlight>
doors optimised(100)
 
=={{header|ALGOL W}}==
'''begin'''
<syntaxhighlight lang="ada">begin
% --''% find the first few squares via the unoptimised door flipping method %''
'''integer''' doorMax;
doorMax := 100;
'''begin'''
''% need to start a new block so the array can have variable bounds %''
''% array of doors - door( i ) is true if open, false if closed %''
'''logical''' '''array''' door( 1 :: doorMax );
''% set all doors to closed %''
'''for''' i := 1 '''until''' doorMax '''do''' door( i ) := '''false''';
''% repeatedly flip the doors %''
'''for''' i := 1 '''until''' doorMax
'''do''' '''begin'''
'''for''' j := i '''step''' i '''until''' doorMax
'''do''' '''begin'''
door( j ) := '''not''' door( j )
'''end'''
'''end''';
''% display the results %''
i_w := 1; ''% set integer field width %''
s_w := 1; ''% and separator width %''
'''for''' i := 1 '''until''' doorMax '''do''' '''if''' door( i ) '''then''' writeon( i )
'''end'''
'''end'''.
 
integer doorMax;
doorMax := 100;
 
begin
% -- need to start a new block so the array can have variable bounds %
 
% -- array of doors - door( i ) is true if open, false if closed %
logical array door( 1 :: doorMax );
 
% -- set all doors to closed %
for i := 1 until doorMax do door( i ) := false;
 
% -- repeatedly flip the doors %
for i := 1 until doorMax
do begin
for j := i step i until doorMax
do begin
door( j ) := not door( j )
end
end;
 
% -- display the results %
i_w := 1; % -- set integer field width %
s_w := 1; % -- and separator width %
for i := 1 until doorMax do if door( i ) then writeon( i )
 
end
 
end.</syntaxhighlight>
{{out}}
<pre>
Line 1,080 ⟶ 1,117:
<syntaxhighlight lang="apl">doors←{100⍴((⍵-1)⍴0),1}
≠⌿⊃doors¨ ⍳100</syntaxhighlight>
{{out}}
<pre>
1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
</pre>
 
'''optimized'''
Line 1,095 ⟶ 1,126:
 
{{works with|Dyalog APL}}
{{works with|GNU APL}}
<syntaxhighlight lang="apl">
≠⌿0=(⍳100)∘.|⍳100</syntaxhighlight>
⍝⍝ Also works with GNU APL after introduction of
 
⍝⍝ the ⍸ function with SVN r1368, Dec 03 2020
Each of the above solutions produces the same output:
⍸≠⌿0=(⍳100)∘.|⍳100</syntaxhighlight>
{{out}}
<pre>
1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 4 9 16 25 36 49 64 81 100
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
</pre>
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1</pre>
 
However the result is obtained, applying the ⍸ function (which has been in Dyalog since 16.0 and was added to GNU APL in SVN r1368, 2020-12-03) will transform the Boolean array into a list of the indices of the true values (open doors):
 
<syntaxhighlight lang="apl">⍸≠⌿0=(⍳100)∘.|⍳100</syntaxhighlight>
{{out}}
<pre>1 4 9 16 25 36 49 64 81 100</pre>
 
=={{header|AppleScript}}==
Line 1,918 ⟶ 1,957:
return(0);
}</syntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* NB: the implementation is rather vanilla
* besides using the idiomatic buffer overrun.
* LOOP is what PERFORM in COBOL is, with defaults.
* MOVE in this language acts like OVE CORRESPONDING,
* which is actually good here.
IDENTIFICATION DIVISION.
PROGRAM-ID. ONE HUNDRED DOORS.
DATA DIVISION.
01 I PICTURE IS 9(3).
01 J LIKE I.
01 DOOR PICTURE IS 9 OCCURS 100 TIMES.
01 STOP LIKE DOOR.
PROCEDURE DIVISION.
* Initialise the data
MOVE HIGH-VALUES TO STOP
MOVE SPACES TO DOOR.
* Do the main algorithm
LOOP VARYING I UNTIL DOOR(I) = 9
LOOP VARYING J FROM I TO 100 BY I
SUBTRACT DOOR (J) FROM 1 GIVING DOOR (J)
END
END.
* Print the results
LOOP VARYING I UNTIL DOOR(I) = 9
DISPLAY "Door" I "is" WITH NO ADVANCING
IF DOOR (I) = 1
THEN DISPLAY "open"
ELSE DISPLAY "closed".
END.
</syntaxhighlight>
 
 
=={{header|BaCon}}==
Line 2,128 ⟶ 2,201:
 
==={{header|Minimal BASIC}}===
{{works with|IS-BASIC}}
<syntaxhighlight lang="qbasic">10 PRINT "FOLLOWING DOORS ARE OPEN:"
20 LET I = 0
Line 2,135 ⟶ 2,209:
60 IF I * I < 100 THEN 30
70 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
Based on the Sinclair ZX81 BASIC implementation.
<syntaxhighlight lang="basic">
10 DIM D(100)
20 FOR I=1 TO 100
30 FOR J=i TO 100 STEP I
40 D(J)=NOT D(J)
50 NEXT J
60 NEXT I
70 FOR I=1 TO 100
80 IF D(I) THEN PRINT I;
90 NEXT I
100 END
</syntaxhighlight>
{{out}}
<pre>
]RUN
1 4 9 16 25 36 49 64 81 100</pre>
 
===QBasic===
Line 2,206 ⟶ 2,299:
180 NEXT I
190 END</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
<syntaxhighlight lang="tiny basic"> PRINT "Open doors are:"
 
LET I = 1
10 IF I = 100 THEN END
rem funcion SQR
LET B = I*I
rem funcion MODULO
LET A = I - (I / B) * B
IF A < 11 THEN PRINT B
LET I = I + 1
GOTO 10</syntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Line 2,218 ⟶ 2,324:
80 IF D(I) THEN PRINT I,
90 NEXT I</syntaxhighlight>
 
==={{header|MSX Basic}}===
Based on the Sinclair ZX81 BASIC implementation.
<syntaxhighlight lang="basic">
10 DIM D(100)
20 FOR I=1 TO 100
30 FOR J=i TO 100 STEP I
40 D(J)=NOT D(J)
50 NEXT J
60 NEXT I
70 FOR I=1 TO 100
80 IF D(I) THEN PRINT I;
90 NEXT I
100 END
</syntaxhighlight>
{{out}}
<pre>
]RUN
1 4 9 16 25 36 49 64 81 100</pre>
 
=={{header|Batch File}}==
Line 2,347 ⟶ 2,434:
;::+1<r]!g9;>$08g1+:08paa[
*`#@_^._aa</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
 
This computes the characteristic sequence of squares by flipping every i'th door in round i, for infinitely many rounds i. But since it's computed lazily and the prefix stabilizes, we can still take the first 100 bits and print them! See corresponding source code at https://github.com/tromp/AIT/blob/master/characteristic_sequences/squares.lam
 
<pre>0001000100010101000110100000010110000011001110110010100011010000000000101111111000000101111101011001011001000110100001111100110100101111101111000000001011111111110110011001111111011100000000101111110000001011111010110011011100101011000000101111011001011110011110011110110100000000001011011100111011110000000001000000111001110100000000101101110110</pre>
 
Output
 
<pre>1001000010000001000000001000000000010000000000001000000000000001000000000000000010000000000000000001</pre>
 
=={{header|Blade}}==
Line 4,508 ⟶ 4,605:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">len d[] 100
len d[] 100
for p = 1 to 100
i = p
while i <= 100
d[i] = 1 - d[i]
i += p
.
.
for i = 1 to 100
if d[i] = 1
print i
.
.
.</syntaxhighlight>
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 5,087 ⟶ 5,186:
 
=={{header|Elena}}==
ELENA 46.0x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 5,093 ⟶ 5,192:
public program()
{
var Doors := Array.allocate(100).populate::(n=>false);
for(int i := 0,; i < 100,; i := i + 1+)
{
for(int j := i,; j < 100,; j := j + i + 1)
{
Doors[j] := Doors[j].Inverted
Line 5,102 ⟶ 5,201:
};
for(int i := 0,; i < 100,; i := i + 1+)
{
console.printLine("Door #",i + 1," :",Doors[i].iif("Open","Closed"))
Line 5,263 ⟶ 5,362:
Door:State state
new by int =id, Door:State =state do end
fun toggle ← <|me.state ← when(me.state æ Door:State.CLOSED, Door:State.OPEN, Door:State.CLOSED)
fun toggle = void by block
fun asText ← <|"Door #" + me.stateid =+ " is " + when(me.state ==æ Door:State.CLOSED, Door:State.OPEN"closed", Door:State.CLOSED"open")
end
fun asText = text by block
return "Door #" + me.id + " is " + when(me.state == Door:State.CLOSED, "closed", "open")
end
end
type Main
^|There are 100 doors in a row that are all initially closed.|^
List doors = Door[].with(100, <int i|Door(i + 1, Door:State.CLOSED))
for int i = 0; i < 100; ++i
doors[i] = Door(i + 1, Door:State.CLOSED)
end
^|You make 100 passes by the doors.|^
for int pass = 0; pass < 100; ++pass
for int i = pass; i < 100; i += pass + 1
doors[i].toggle()
end
Line 5,284 ⟶ 5,376:
^|Which are open, which are closed?|^
for each Door door in doors
if door.state ==æ Door:State.CLOSED do continue end
writeLine(door)
end
Line 5,397 ⟶ 5,489:
=={{header|Euler}}==
In Euler, all variables have the value <code>undefined</code> until assigned another value. <code>isu x</code> returns <code>true</code> if x is currently undefined and the and/or operators short-circuit.
'''begin''' '''new''' doors; '''new''' i; '''label''' doorLoop; '''label''' outDoors;
<syntaxhighlight lang="euler">
begin new doors; new i; label doorLoop doors &lt;- label'''list''' outDoors100;
doors <-i list 100 &lt;- 0;
doorLoop: '''if''' [ i &lt;- i + 1 ] &lt;= '''length''' doors '''then''' '''begin'''
i <- 0;
'''new''' j; '''label''' flipLoop;
doorLoop: if [ i <- i + 1 ] <= length doors then begin
new j; label flipLoop&lt;- 0;
flipLoop: '''if''' [ j &lt;- J + i ] &lt;= '''length''' doors '''then''' '''begin'''
j <- 0;
flipLoop: if doors[ j <] &lt;- J'''isu''' +doors[ ij ] <='''or''' length'''not''' doors[ thenj begin];
doors[ j'''goto''' ] <- isu doors[ j ] or not doors[ j ];flipLoop
'''end''' '''else''' goto flipLoop0;
end else'''goto''' 0;doorLoop
'''end''' '''else''' goto doorLoop0;
end elsei &lt;- 0;
outDoors: '''if''' [ i &lt;- i + 1 ] &lt;= '''length''' doors '''then''' '''begin'''
i <- 0;
outDoors: if [ i <- i + 1 ] <= length '''if''' doors[ i ] '''then''' '''out''' i '''else''' begin0;
if doors['''goto''' i ] then out i else 0;outDoors
'''end''' '''else''' goto outDoors0
'''end''' $
end else 0
end $
</syntaxhighlight>
 
=={{header|Euler Math Toolbox}}==
Line 6,192 ⟶ 6,282:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/100_doors}}
 
'''Solution'''
 
The solution consists in having a 100 element array, initialized with FALSE values. In each of the 100 rounds (controlled by a simple FOR-FROM-TO cycle), the values are flipped using a FOR-FROM-TO-STEP cycle. Finally the array is shown, using green colors for open doors, and red for closed ones. The resulting matrix is transposed in order to be shown horizontally.
Line 6,198 ⟶ 6,290:
 
The result of calling the function is:
 
[[File:Fōrmulæ - 100 doors 06.png]]
 
[[File:Fōrmulæ - 100 doors 02.png]]
 
Improvement:'''Improvements. Graphic output, in order to show evolution in time, and an arbitrary number of doors.'''
 
[[File:Fōrmulæ - 100 doors 03.png]]
Line 6,651 ⟶ 6,745:
 
=={{header|Haxe}}==
 
===Unoptimised===
<syntaxhighlight lang="haxe">
class Main
{
static public function main()
{
findOpenDoors( 100 );
}
 
static function findOpenDoors( n : Int )
{
var door = [];
for( i in 0...n + 1 ){ door[ i ] = false; }
for( i in 1...n + 1 ){
var j = i;
while( j <= n ){
door[ j ] = ! door[ j ];
j += i;
}
}
for( i in 1...n + 1 ){
if( door[ i ] ){ Sys.print( ' $i' ); }
}
}
}</syntaxhighlight>
{{out}}
<pre>
1 4 9 16 25 36 49 64 81 100
</pre>
 
===Optimised===
 
<syntaxhighlight lang="haxe">class RosettaDemo
{
Line 6,664 ⟶ 6,791:
while((i*i) <= n)
{
Sys.printprintln(i*i + "\n");
i++;
}
Line 6,911 ⟶ 7,038:
END MAIN
</syntaxhighlight>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(var doors (times 100 false))
 
(for i (range 1 101)
i2 (range (dec i) 100 i)
(var! doors (set-at [i2] (! (i2 doors))))
(continue))
 
(-> (xmap vec doors)
(filter 1)
(map (comp 0 inc))
(join ", ")
@(str "open doors: "))
</syntaxhighlight>
 
{{out}}
 
<pre>
open doors: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
</pre>
 
=={{header|Io}}==
Line 7,424 ⟶ 7,574:
}
});</syntaxhighlight>
{{works with|SpiderMonkey}}(Firefox) But not most (if any) other JavaScript engines. Array comprehension (<code>[ for... ]</code>) is non-standard.
 
 
<syntaxhighlight lang="javascript">// Array comprehension style
[ for (i of Array.apply(null, { length: 100 })) i ].forEach((_, i) => {
Line 7,432 ⟶ 7,581:
 
if (sqrt === (sqrt | 0)) {
console.log("Door %d" + door + " is open", door);
}
});</syntaxhighlight>
Line 7,754 ⟶ 7,903:
=={{header|langur}}==
=== not optimized ===
<syntaxhighlight lang="langur">var .doors = [false] * 100
{{works with|langur|0.8}}
<syntaxhighlight lang="langur">var .doors = arr 100, false
 
for .i of .doors {
Line 7,766 ⟶ 7,914:
 
Or, we could use the foldfrom() function to produce the output.
<syntaxhighlight lang="langur">writeln foldfrom(ffn(.a, .b, .c) { if(.b: .a~[.c]; .a) }, [], .doors, series 1..len .doors)</syntaxhighlight>
 
=== optimized ===
<syntaxhighlight lang="langur">writeln map(f .x fn{^ 2}, series 1..10)</syntaxhighlight>
 
{{works with|langur|0.8.11}}
<syntaxhighlight lang="langur">writeln map f{^2}, 1..10</syntaxhighlight>
 
{{out}}
Line 8,201 ⟶ 8,346:
end
a
</syntaxhighlight>
'''Optimized - Alternative'''
<syntaxhighlight lang="matlab">
doors = zeros(1,100); // 0: closed 1: open
for i = 1:100
doors(i:i:100) = 1-doors(i:i:100)
Line 9,061 ⟶ 9,207:
echo outputString</syntaxhighlight>
 
=={{header|Oberon-07}}==
[http://oberon07.com/ Oberon-07], by [http://people.inf.ethz.ch/wirth/index.html Niklaus Wirth].
<syntaxhighlight lang="oberonmodula2">MODULE Doors;
IMPORT Out;
Line 11,278 ⟶ 11,424:
 
'''ultra-optimized''': ported from Julia version<br>
<syntaxhighlight lang="python">for i in range(1,10111): print("Door %s is open" % i**2)</syntaxhighlight>
 
=={{header|Q}}==
Line 11,601 ⟶ 11,747:
repeat n len [if doors/:n [print n]]
</syntaxhighlight>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Show 1 <Walk 1 <Doors>>>;
};
 
NDoors { = 100; };
Doors { = <Repeat <NDoors> Closed>; };
 
Repeat {
0 s.val = ;
s.N s.val = s.val <Repeat <- s.N 1> s.val> ;
};
 
Toggle {
1 Closed e.rest = Open e.rest;
1 Open e.rest = Closed e.rest;
s.N s.door e.rest = s.door <Toggle <- s.N 1> e.rest>;
};
Pass {
s.pass s.door e.doors, <Compare s.door <NDoors>>: '+'
= e.doors;
s.pass s.door e.doors
= <Pass s.pass <+ s.pass s.door> <Toggle s.door e.doors>>;
};
 
Walk {
s.pass e.doors, <Compare s.pass <NDoors>>: '+'
= e.doors;
s.pass e.doors
= <Walk <+ s.pass 1> <Pass s.pass s.pass e.doors>>;
};
 
Show {
s.N Open e.rest = <Prout Door s.N is open>
<Show <+ s.N 1> e.rest>;
s.N Closed e.rest = <Show <+ s.N 1> e.rest>;
s.N = ;
};</syntaxhighlight>
{{out}}
<pre>Door 1 is open
Door 4 is open
Door 9 is open
Door 16 is open
Door 25 is open
Door 36 is open
Door 49 is open
Door 64 is open
Door 81 is open
Door 100 is open</pre>
 
=={{header|Relation}}==
Line 13,194 ⟶ 13,391:
| 100 |
+-------+</syntaxhighlight>
 
=={{header|Stringle}}==
<syntaxhighlight lang="stringle">d "."
#d
i d
#i
p "door" #i
*p *p "."
i d f "oc"
i d #@f #*p
i d .\f "o" $ #i
i i d
#i +101 i ""
#i
d d "."
#d +101 d ""
#d</syntaxhighlight>
{{out}}
<pre>1
4
9
16
25
36
49
64
81
100</pre>
 
=={{header|SuperCollider}}==
Line 13,251 ⟶ 13,476:
println("Door \(index+1) is \(item.rawValue)")
}</syntaxhighlight>
===One-liner===
<syntaxhighlight lang="swift">
var arr: [Bool] = Array(1...100).map{ remquo(exp(log(Float($0))/2.0),1).0 == 0 }
</syntaxhighlight>
 
=={{header|Tailspin}}==
Line 13,790 ⟶ 14,019:
100 = open
</pre>
 
=={{Header|Tiny BASIC}}==
<syntaxhighlight lang="tiny basic"> PRINT "Open doors are:"
 
LET I = 1
10 IF I = 100 THEN END
rem funcion SQR
LET B = I*I
rem funcion MODULO
LET A = I - (I / B) * B
IF A < 11 THEN PRINT B
LET I = I + 1
GOTO 10</syntaxhighlight>
 
=={{header|Tiny Craft Basic}}==
<syntaxhighlight lang="basic">10 rem loop
 
20 let i = i + 1
30 print i * i, " open"
 
40 if i * i < 100 then 10
 
50 shell "pause"
60 end</syntaxhighlight>
 
=={{header|TypeScript}}==
Line 14,605 ⟶ 14,810:
=={{header|Wren}}==
'''Unoptimized'''
<syntaxhighlight lang="ecmascriptwren">var doors = [true] * 100
for (i in 1..100) {
var j = i
Line 14,620 ⟶ 14,825:
 
'''Optimized'''
<syntaxhighlight lang="ecmascriptwren">var door = 1
var increment = 3
while (door <= 100) {
Line 14,883 ⟶ 15,088:
Optimized
<syntaxhighlight lang="yabasic">for i = 1 to sqrt(100) : print "Door ", i**2, " is open" : next</syntaxhighlight>
 
 
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
!yamlscript/v0
 
defn main():
say: |-
Open doors after 100 passes:
$(apply str interpose(', ' open-doors()))
 
defn open-doors():
for [[d n] map(vector doors() iterate(inc 1)) :when d]:
n
 
defn doors():
reduce:
fn(doors idx): assoc(doors idx true)
into []: repeat(100 false)
map \(dec (%1 * %1)): 1 .. 10
</syntaxhighlight>
{{out}}
<pre>
$ ys 100-doors.ys
Open doors after 100 passes: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
</pre>
 
=={{header|Yorick}}==
Line 14,946 ⟶ 15,177:
===Optimized with new for-loop (since Zig 0.11)===
<syntaxhighlight lang="zig">
const stdout = @import("std").io.getStdOut().writer();
 
pub fn main() !void {
const stdout = @import("std").io.getStdOut().writer();
 
var square: u8 = 1;
var increment: u8 = 3;
Line 14,961 ⟶ 15,192:
</syntaxhighlight>
 
===RealyReally Optimized===
<syntaxhighlight lang="zig">
const stdout = @import("std").io.getStdOut().writer();
 
pub fn main() !void {
const stdout = @import("std").io.getStdOut().writer();
 
var door: u8 = 1;
while (door * door <= 100) : (door += 1) {
Line 14,971 ⟶ 15,202:
}
}
 
</syntaxhighlight>{{out}}
<pre>Door 1 is open.
885

edits