Conway's Game of Life: Difference between revisions

Jump to navigation Jump to search
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 4: Line 4:
<source lang=apl>
<source lang=apl>
       life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
       life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
</source>
</syntaxhighlight>
This implementation is also explained [[John Scholes' Conway's Game of Life|in its own article]].
This implementation is also explained [[John Scholes' Conway's Game of Life|in its own article]].


Line 19: Line 19:
⍝ APL2
⍝ APL2
lfe:((2×+⌿⊃¯1 0 1⊖¨+⌿¯1 0 1⌽¨⊂⍵)-⍵)∊5 6 7
lfe:((2×+⌿⊃¯1 0 1⊖¨+⌿¯1 0 1⌽¨⊂⍵)-⍵)∊5 6 7
</source>
</syntaxhighlight>
McDonnell also described how future language features, such as the [[Commute]] operator and a tesselation operator related to [[Cut (operator)|Cut]] and the much later [[Stencil]], might reduce this to as few as 11 tokens (one of which is a long list of integers), or to 9 tokens when using a pre-defined vector of matrices.
McDonnell also described how future language features, such as the [[Commute]] operator and a tesselation operator related to [[Cut (operator)|Cut]] and the much later [[Stencil]], might reduce this to as few as 11 tokens (one of which is a long list of integers), or to 9 tokens when using a pre-defined vector of matrices.


Cliff Reiter's 2005 article "Time(r) for the Game of Life"<ref>Cliff Reiter. [http://archive.vector.org.uk/art10007290 "Time(r) for the Game of Life"]. [[Vector journal]] Volume 21 Number 3. 2005-05.</ref> studies the performance of several [[J]] implementations, including both methods based on [[Cut (operator)|Cut]] and one by Ewart Shaw more similar to McDonnell's Rotate-based strategies, finding the latter to be much faster. He also includes a survey of APL-family Life implementations since "Life: Nasty, Brutish, and Short".
Cliff Reiter's 2005 article "Time(r) for the Game of Life"<ref>Cliff Reiter. [http://archive.vector.org.uk/art10007290 "Time(r) for the Game of Life"]. [[Vector journal]] Volume 21 Number 3. 2005-05.</ref> studies the performance of several [[J]] implementations, including both methods based on [[Cut (operator)|Cut]] and one by Ewart Shaw more similar to McDonnell's Rotate-based strategies, finding the latter to be much faster. He also includes a survey of APL-family Life implementations since "Life: Nasty, Brutish, and Short".


[[John Scholes]] published a video in which he explains his own implementation of Life, the same as the function <source lang=apl inline>Life</source> above, in 2009.<ref name="scholes"/> Scholes' function resembles McDonnell's APL2 implementation in its use of three-element vertical and horizontal rotation vectors, but uses [[Inner Product]] and [[Outer Product]] rather than [[Each]] as well as a different arithmetic scheme.
[[John Scholes]] published a video in which he explains his own implementation of Life, the same as the function <source lang=apl inline>Life</syntaxhighlight> above, in 2009.<ref name="scholes"/> Scholes' function resembles McDonnell's APL2 implementation in its use of three-element vertical and horizontal rotation vectors, but uses [[Inner Product]] and [[Outer Product]] rather than [[Each]] as well as a different arithmetic scheme.


When introducing the [[Stencil]] operator in [[Dyalog APL 16.0]], [[Roger Hui]] presented several Game of Life implementations using the new primitive.<ref>[[Roger Hui]]. [https://www.dyalog.com/blog/2017/07/stencil-lives/ "Stencil Lives"]. 2017-07-31.</ref> These included [[Jay Foad]]'s function <source lang=apl inline>{3=s-⍵∧4=s←{+/,⍵}⌺3 3⊢⍵}</source>, translated from [[Arthur Whitney]]'s [[K]] implementation <source lang=apl inline>{3=s-x&4=s:2(+-1+/':)/x}</source>.<ref>[[Arthur Whitney]]. [http://kparc.com/z/fun.k "fun.k"].</ref>
When introducing the [[Stencil]] operator in [[Dyalog APL 16.0]], [[Roger Hui]] presented several Game of Life implementations using the new primitive.<ref>[[Roger Hui]]. [https://www.dyalog.com/blog/2017/07/stencil-lives/ "Stencil Lives"]. 2017-07-31.</ref> These included [[Jay Foad]]'s function <source lang=apl inline>{3=s-⍵∧4=s←{+/,⍵}⌺3 3⊢⍵}</syntaxhighlight>, translated from [[Arthur Whitney]]'s [[K]] implementation <source lang=apl inline>{3=s-x&4=s:2(+-1+/':)/x}</syntaxhighlight>.<ref>[[Arthur Whitney]]. [http://kparc.com/z/fun.k "fun.k"].</ref>


Conway's Game of Life featured as one of the problems in the APL [[Code golf|Code Golf]] Autumn Tournament, an event jointly run by [[Dyalog Ltd.]] and Optima Systems Ltd. In a follow-up [[Dyalog webinar]], [[Adám Brudzewsky]] presented both the game and one of the winning 17-character solutions (<source lang=apl inline>{≢⍸⍵}⌺3 3∊¨3+0,¨⊢</source>) in detail.<ref>[[Gitte Christensen]] & [[Adám Brudzewsky]]. [https://dyalog.tv/Webinar/?v=3FjYly2G_QI "Dyalog Webinars: APL CodeGolf Autumn Tournament"]. 2017-10-26.</ref>
Conway's Game of Life featured as one of the problems in the APL [[Code golf|Code Golf]] Autumn Tournament, an event jointly run by [[Dyalog Ltd.]] and Optima Systems Ltd. In a follow-up [[Dyalog webinar]], [[Adám Brudzewsky]] presented both the game and one of the winning 17-character solutions (<source lang=apl inline>{≢⍸⍵}⌺3 3∊¨3+0,¨⊢</syntaxhighlight>) in detail.<ref>[[Gitte Christensen]] & [[Adám Brudzewsky]]. [https://dyalog.tv/Webinar/?v=3FjYly2G_QI "Dyalog Webinars: APL CodeGolf Autumn Tournament"]. 2017-10-26.</ref>


== External links ==
== External links ==

Navigation menu