4 ms·
Cool article, but it does go through a lot of effort (copying a string many times and then executing it) in order to get a loop on one line. In modern APL we'd
by mlochbaum 7y ago
Cool article, but it does go through a lot of effort (copying a string many times and then executing it) in order to get a loop on one line. In modern APL we'd just use the Power operator (⍣), which repeats a function. The dfn {⎕←Life ⍵} gets the next iteration and displays it, so {{⎕←Life⍵}⍣⍺⊢⍵} does this ⍺ times, where ⍺ is the left argument (the ⊢ is the identity function: all it does it to prevent ⍺ and ⍵ from being stranded together into one array). If we want space between the iterations, we can print an empty line first, with {{⎕←''⋄⎕←Life⍵}⍣⍺⊢⍵}. Substituting in the definition of Life, we have
RepLife ← {{⎕←''⋄⎕←↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}⍣⍺⊢⍵}
Try it with
10 RepLife ¯10 ¯10↑3 3⍴1 1 1 1 0 0 0 1 0
Another old paper on the Game of Life is Eugene McDonnell's "Life: Nasty, Brutish, and Short" (https://www.jsoftware.com/papers/eem/life.htm https://www.jsoftware.com/papers/eem/life.htm). This was where John Scholes got the idea of doing three rotations along each dimension. Interestingly, McDonnell attributes the idea to an implementation by Don Knuth in METAFONT!