Forum Discussion
Utilizing Excel's turing capabilities to create Conway's 'Game of Life'
Patrick2788 Interesting. I remember doing this in machine code on my Comodore64 in the late 70's. Especially the famous 'Slider' figure that just continues to in a sequence of repeating patterns. It can be seen in the wiki link you provided.
The start is like this:
The 2nd generation becomes:
And the third should be like below though the red cells do not become alive in your formula:
Stepping back to the previous state and highlighting these two red cells, and it's clear that they should become alive in the next generation as the both have three neighbors that are alive at the time. Or have I misunderstood?
- Patrick2788Jan 26, 2024Silver ContributorThank you for taking a look. I've determined the 'SW' check is missing. The formula sees the cell as 0 with the neighbors for the cell at 2 so it's not making it live. If I'm able to have some uninterrupted time at work I may be able to fix it.
- Patrick2788Jan 27, 2024Silver Contributor
I've updated the Conway Lambda in the first post and replaced the workbook. The issue was IFERROR was resolving to "" when it should have been 0.
In re:
Stepλ(board) =LAMBDA(r, c, LET( n, 18, state, INDEX(board, r, c), onboard, SIGN(MOD(r + δr, n + 1)) * SIGN(MOD(c + δc, n + 1)), count, SUM(IF(onboard, INDEX(board, r + δr, c + δc), 0)) - state, IF(state, SUM(SIGN(count = {2, 3})), SIGN(count = 3)) ) )
This a really clever use of the functions available! I like how you've really simplified the logic by approaching it this way. My use of IF-AND-OR is slowing calculations a bit.
Below is my MAKEARRAY version. I've compared the results up to 20 iterations against my original and Peter's solution and they're identical.
'Conway with MAKEARRAY =LAMBDA(matrix,iterations,IF( iterations = 0, matrix, Conway( LET( height, ROWS(matrix), width, COLUMNS(matrix), CheckNeighbors, LAMBDA(r, c, LET( grid_val, INDEX(matrix, r, c), ext_rows, SEQUENCE(3, , r - 1), ext_cols, SEQUENCE(, 3, c - 1), Square3x3, INDEX(matrix, ext_rows, ext_cols), neighbors, IF( OR(r = 1, c = 1, r = height, c = width), 0, SUM(Square3x3) - grid_val ), IF( AND(grid_val = 0, neighbors = 3), 1, IF(AND(grid_val = 1, OR(neighbors = 2, neighbors = 3)), 1, 0) ) ) ), MAKEARRAY(height, width, CheckNeighbors) ), iterations - 1 ) ))
My goal was to simplify things - mainly the directional checks. For this version I'm supplying the Lambda with a 'padded' matrix:
With MAKEARRAY I then 'offset' from the 'grid-val' with INDEX and the rest becomes simpler.
- Patrick2788Jan 29, 2024Silver Contributor
Here are the timings for each solution:
timer used: vba - fullrecalc
100 iterations - average of 5 times
Original - 3.33 seconds
PB - .6189 seconds
MAKEARRAY- .8585 seconds
- on a 36x150 board - 10 iterations - about 8 seconds