Conway's Game of Life: Difference between revisions

Jump to navigation Jump to search
More context in introduction
(More context in introduction)
Line 1: Line 1:
'''[[wikipedia:Conway's Game of Life|Conway's Game of Life]]''' is a well-known cellular automaton in which each generation of a population 'evolves' from the previous one according to a set of predefined rules.
'''[[wikipedia:Conway's Game of Life|Conway's Game of Life]]''' is a well-known cellular automaton in which each generation of a population "evolves" from the previous one according to a set of predefined rules. The Game of Life is defined on an infinite [[Boolean]] grid, but usually only finite patterns, where all 1 values fit in a finite Boolean [[matrix]], are studied. Because it involves interactions between adjacent [[elements]] of the matrix, and can take advantage of APL's convenient and fast Boolean handling, implementing the Game of Life is a popular activity for APLers. Published APL implementations have appeared since 1971, a year after the rules of the Game of Life were first published.
 
Here is [[John Scholes]]' famous one-line APL function takes a boolean [[matrix]] as argument and returns a boolean matrix with the new generation.


A famous video by [[John Scholes]]<ref name="scholes">[[John Scholes|Scholes, John]]. [https://www.youtube.com/watch?v=a9xAKttWgP4 "Conway's Game of Life in APL"]. 2009-01-26.</ref> explains the following [[Dyalog APL]] implementation step by step. The implementation takes advantage of [[nested]] arrays and the [[Outer Product]] to produce many copies of the argument array. It finds adjacent elements by [[Rotate|rotating]] the original array, causing elements at the edge to wrap around (giving a torus geometry).
<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>
</source>
This implementation is also explained [[#How Scholes' implementation works|later in this article]].


== The Glider ==
== The Glider ==
Line 86: Line 86:
</source>
</source>


== How the APL code works ==
== How Scholes' implementation works ==
If you're completely new to APL, this explanation is probably not the place to start, rather check out our [[Tutorials#Introductions|introductions]]. However, you should be able to get some idea of what's happening even if the details are not yet clear. Just bear in mind that APL evaluates expressions from right to left unless you use parentheses.
If you're completely new to APL, this explanation is probably not the place to start, rather check out our [[Tutorials#Introductions|introductions]]. However, you should be able to get some idea of what's happening even if the details are not yet clear. Just bear in mind that APL evaluates expressions from right to left unless you use parentheses.


Line 256: Line 256:
A survey of previous APL implementations along with two new 23-token implementations was given by [[Eugene McDonnell]] in "Life: Nasty, Brutish, and Short", published in the [[APL88]] conference proceedings.<ref>[[Eugene McDonnell|McDonnell, Eugene]]. [https://www.jsoftware.com/papers/eem/life.htm "Life: Nasty, Brutish, and Short"]. APL88 Conference Proceedings, '''APL Quote-Quad''' Vol. 18 No. 2, 1987-12.</ref> 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.
A survey of previous APL implementations along with two new 23-token implementations was given by [[Eugene McDonnell]] in "Life: Nasty, Brutish, and Short", published in the [[APL88]] conference proceedings.<ref>[[Eugene McDonnell|McDonnell, Eugene]]. [https://www.jsoftware.com/papers/eem/life.htm "Life: Nasty, Brutish, and Short"]. APL88 Conference Proceedings, '''APL Quote-Quad''' Vol. 18 No. 2, 1987-12.</ref> 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.


[[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>[[John Scholes|Scholes, John]]. [https://www.youtube.com/watch?v=a9xAKttWgP4 "Conway's Game of Life in APL"]. 2009-01-26.</ref> 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</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.


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

Navigation menu