Forum Discussion
Patrick2788
Jan 25, 2024Silver Contributor
Utilizing Excel's turing capabilities to create Conway's 'Game of Life'
The Background It's been said with Lambda (and LET and a wealth of functions in 365) Excel has become 'turing-complete'. To quote the article linked below: "You can now, in principle, write any co...
m_tarler
Feb 01, 2024Bronze Contributor
Patrick2788 Again a fun and interesting challenge but I went a very different route (I know imagine that). Here is my solution without any LAMBDA inside:
LIFE=LAMBDA(matrix, iterations,
LET(
matrix2, IF(iterations > 1, Life(matrix, iterations - 1), matrix),
m, IFERROR(VSTACK(0, HSTACK(0, matrix2, 0), 0), 0),
neighbors, VSTACK(0, HSTACK(0, m)) + VSTACK(0, m) + VSTACK(0, DROP(m, , 1)) + DROP(m, , 1) +
HSTACK(0, m) + HSTACK(0, DROP(m, 1)) + DROP(m, 1) + DROP(m, 1, 1),
alive_neighbors, neighbors * m,
--DROP(
DROP(((neighbors = 3) + ((alive_neighbors > 1) * (alive_neighbors < 4)) > 0), 1, 1),
-2,
-2
)
)
Patrick2788
Feb 02, 2024Silver Contributor
I like the way you terminate the loop immediately within the first parameter ('matrix2') of LET. My usual go-to is terminating the function with an IF before the function is called in predicable fashion. It's good to see it done smoothly with your formula.
Pad the matrix to make sure each cell has 8 adjacent cells and some clever stacking and addition to find the neighbors. The use of DROP here is a throwback to ctrl+shift+enter arrays and it's elegant here and no logical IF/AND/OR needed! I like the economy of this formula. Thanks for sharing!