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...
Patrick2788
Apr 03, 2025Silver Contributor
This updated approach for 2025 uses a kernel and MAP to do the heavy lifting. I tend to err on the side of more parameters and readability.
//Kernel coordinates:
x = {-1;-1;-1;0;1;1;1;0};
y = {-1;0;1;1;1;0;-1;-1};
//A simulation of Conway's Game of Life
Conwayλ =
LAMBDA(config,n,
LET(
//determine dimensions of the board
h,ROWS(config),
w,COLUMNS(config),
//create matrices of coordinates
i,SEQUENCE(h)*SEQUENCE(,w,1,0),
j,TRANSPOSE(i),
//determine if cell is to be kept or discarded
generate,MAP(i,j,LAMBDA(i_,j_,
LET(
each_cell,INDEX(config,i_,j_),
//generate coordinates for each cell
//discard certain coordinates if cell is on perimeter of board
kernel,(i_+ x>0)*(j_+y>0)*(i_+ x<=h)*(j_+y<=w),
r,FILTER(i_ + x,kernel),
c,FILTER(j_+ y, kernel),
//total the neigbors
neighbors,SUM(INDEX(config,r,c)),
//cell is 0 but has exactly 3 neighbors - keep
revive,(each_cell=0)*(neighbors=3),
//cell is alive and has 2 or 3 neighbors - keep
keep,(each_cell=1)*(neighbors=2)+(neighbors=3),
IF(revive,1,IF(keep,1,0))))),
IF(n=0,config,Conwayλ(generate,n-1))))