100 doors: Difference between revisions
→{{header|APL}}: Make third solutions produce same output; add note that ⍸ can be added to either.
m (→{{header|Oberon}}: Fixed language name and use Modula-2 for syntax highlighting) |
(→{{header|APL}}: Make third solutions produce same output; add note that ⍸ can be added to either.) |
||
Line 1,117:
<syntaxhighlight lang="apl">doors←{100⍴((⍵-1)⍴0),1}
≠⌿⊃doors¨ ⍳100</syntaxhighlight>
{{out}}▼
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▼
'''optimized'''
Line 1,132 ⟶ 1,126:
{{works with|Dyalog APL}}
{{works with|GNU APL}}
<syntaxhighlight lang="apl">
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
▲ 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}}==
|