I have a love-hate relationship with APLs. On one hand, they’re unbelievably powerful in what they can do. On the other hand, they’re abso

The Jame of Life

submited by
Style Pass
2021-05-21 09:30:06

I have a love-hate relationship with APLs. On one hand, they’re unbelievably powerful in what they can do. On the other hand, they’re absolutely awful in what they can’t do. I always feel like I’m walking that thin line between brilliant and stupid.

It’s Conway’s Game of Life, done in under 40 characters, “with no explicit loops and no temporary variables”. By contrast, The corresponding Java code is 22 lines and over 500 characters. This is a really impressive demonstration of APL’s power, how it almost borders on magical.

I don’t know APL, but I know J, one of its spiritual successors.1 Last Friday, out of curiosity, I wanted to see if I could write GoL too. I had it within 30 minutes:

A quick overview of how the algorithm works. The game of life board is stored as a matrix, where 1 represents a live cell and 0 represents an empty space. We shift the matrix one space in all eight cardinal directions (NW, N, NE, etc), generating eight new matrices, and add all of them elementwise to the original board.2

Leave a Comment