Forum Discussion
Utilizing Excel's turing capabilities to create Conway's 'Game of Life'
You have prompted me to have another go. I have made some minor changes to your solution such as using REDUCE rather than recursion and a DROP/TAKE combination to isolate neighbourhoods.
The fun step was then to switch REDUCE to SCAN and produce the result as an array of thunks. That allows the user to iterate the board in place or display the entire sequence of results.
Worksheet formula
= LET(
result, SCAN(THUNK(board), SEQUENCE(generations), Stepλ),
EVALTHUNKARRλ(IF(ShowAll, result, TAKE(result,-1)))
)
//A simulation of Conway's Game of Life
Stepλ
=LAMBDA(gridϑ, k,
LET(
grid, gridϑ(),
life, MAKEARRAY(
ROWS(grid),
COLUMNS(grid),
LAMBDA(r, c,
LET(
border?, OR(r=1, c=1, r=ROWS(grid), c=COLUMNS(grid)),
// Identify neighbourhood and cell state
neighbourhood, TAKE(DROP(grid, r - 2, c - 2), 3, 3),
alive, INDEX(neighbourhood, 2, 2),
//total the neighbours
count, SUM(neighbourhood) - alive,
//cell has 3 neighbors or is alive and has 2 neighbors - keep
IF(border?, "x", alive * (count = 2) + (count = 3))
)
)
),
THUNK(life))
);
This is a clever approach to a situation that on the surface appears to only be solvable with recursion. As I understand it:
The board is thunked immediately and provided as the initial value (It's a good way to "fit a matrix through a scalar-sized keyhole"). I like how SCAN does its work on {1;2;3...} instead of having to accept the entire board. 'k' appears to arbitrary in that it fulfills a parameter but SCAN is only concerned with the accumulated matrix. Due to the limitations of SCAN, the result must be thunked (because it can't yet be properly evaluated) and unpacked with EVALTHUNKARRλ.
I may try this approach with of few of the Wolfram rules that use a starting configuration of {0,1,0} that can be solved with recursion and a few bit functions. It's probably not needed but it's the experimentation that's fun!
- PeterBartholomew1Apr 09, 2025Silver Contributor
Nice description!
The array of thunks allows a reasonable level of customisation of the layout as well. For example
= LET( resultϑ, SCAN(THUNK(board), SEQUENCE(generations), Stepλ), EVALTHUNKARRλ(IF(ShowAll, WRAPROWS(resultϑ,5), TAKE(resultϑ,-1))) )
will arrange the display to have 5 boards across each row. I also changed the spinner to increment in fives.
- Patrick2788Apr 10, 2025Silver Contributor
This is a good example of how thunks can be efficient. The timings are roughly each 250 generations = 2.5 seconds. This is impressive considering how much is involved in the calculations.
My only regret with my solution is the reliance on INDEX (and subsequently, FILTER). The performance is decent but I'd rather not have to deal with discarding 0s so INDEX doesn't go haywire.
One of things I've been experimenting with is a function that can selectively traverse a matrix. The idea is the function would be deployed while mapping or using MAKEARRAY on a matrix. For each given element in the matrix, the function would traverse up, down, right, left, etc. This is all part of a larger project in attempting to solve Matrix Flow Accumulation - something Excel probably has no business in doing because there are programs that do it, but it is certainly interesting!
- PeterBartholomew1Apr 10, 2025Silver Contributor
If I was allowed to write a Fast Fourier Transform algorithm in Excel, I don't see why you shouldn't play with Matrix Flow!