3 ms·
I'm a sucker for GPT3. In his weekly column the famous IT philosopher explains issues in computation in a very thoughtful manner. Recently, Conway's Game of L
by isaacfrond 4y ago
I'm a sucker for GPT3.
In his weekly column the famous IT philosopher explains issues in computation in a very thoughtful manner.
Recently, Conway's Game of Life was implemented as a one-liner in APL executed in FORTH. APL is another weird-looking programming language. Implementing Conway's game of Life yet again is important because it is a fundamental example of a computation. In this case, the one-liner is important because it is an example of how to concisely express a computation.
Conway's Game of Life is a cellular automaton. A cellular automaton is a discrete model of computation. It consists of a grid of cells, each of which can be in one of a finite number of states. The state of the automaton is updated in discrete time steps, according to a fixed rule. In Conway's Game of Life, the rule is that a cell is alive in the next time step if and only if it was alive in the previous time step and exactly two or three of its eight neighbors were also alive. If a cell is not alive in the previous time step, then it is alive in the next time step if and only if exactly three of its neighbors were alive.
The one-liner in APL executes the Game of Life rule on a two-dimensional grid of cells. The input to the one-liner is the state of the grid at some time step, and the output is the state of the grid at the next time step. The one-liner is able to do this because it uses a clever trick. It treats the input grid as a one-dimensional array of cells, and it uses the fact that the Game of Life rule can be expressed as a matrix operation.
The one-liner is:
life←{↑1 ⍵∨.↑1 3 4⍵}
This one-liner is an example of how to concisely express a computation. It is also an example of how to use a powerful programming language to express a computation in a simple and elegant way.
- Stratoscope 4y agoWhoever wrote that is much smarter than me!
- shagie 4y agoIt isn't so much a "the author of that one liner is way smarter" but rather "the language features of APL naturally fit this problem space."
- exikyut 4y agoI didn't notice it initially but (part of) the two top lines are italicized. Presumably this was the input prompt. Which is kind of cool to be able to look at and observe that it made that from just those specific 48 input words. Huh.
- tromp 4y agoThat looks like a butchered version of life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵} as shown at https://aplwiki.com/wiki/Conway%27s_Game_of_Life https://aplwiki.com/wiki/Conway%27s_Game_of_Life
- deleted 4y ago[deleted]