John Scholes' Conway's Game of Life: Difference between revisions

Jump to navigation Jump to search
Translations to GNU and dzaima/APL
(Expand on introduction)
(Translations to GNU and dzaima/APL)
Line 254: Line 254:


The final expression ends with a bit of housekeeping using [[Mix]] (<source lang=apl inline>↑</source>) to turn the result back into a simple array (it's currently nested).
The final expression ends with a bit of housekeeping using [[Mix]] (<source lang=apl inline>↑</source>) to turn the result back into a simple array (it's currently nested).
== Translations ==
=== GNU APL ===
In [[GNU APL]] the [[Inner Product]] <source lang=apl inline>∨.∧</source> results in a twice-[[enclose]]d matrix, rather than once-enclosed as in [[Dyalog APL]]. This can be fixed either by [[mix]]ing twice, or by using a [[Reduce|reduction]] instead of an inner product.
<source lang=apl>
      Life←{↑↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}
      Life←{↑∨/1 ⍵∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}
</source>
=== dzaima/APL ===
In [[dzaima/APL]] the [[Reduce|reduction]] <source lang=apl inline>+/</source> [[mix]]es its result, which defeats our use of [[scalar extension]] causing a [[LENGTH ERROR]]. Because the sum has only one (matrix) result, enclosing it corrects this issue.
<source lang=apl>
      Life←{↑1 ⍵∨.∧3 4=⊂+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}
</source>
The computation of our example <source lang=apl inline>grid</source> also fails, because dzaima's [[Take]] does not allow overtaking. Instead we can insert the glider into a matrix of zeros using [[structural Under]]:
<source lang=apl>
      grid ← ¯10 ¯10↑glider            ⍝ DomainError
      grid ← glider⍢(¯3 ¯3∘↑) 10 10⍴0  ⍝ This works
</source>


== References ==
== References ==
<references />
<references />

Navigation menu