How to resolve the algorithm Conway's Game of Life step by step in the 11l programming language
How to resolve the algorithm Conway's Game of Life step by step in the 11l programming language
Table of Contents
Problem Statement
The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is the best-known example of a cellular automaton. Conway's game of life is described here: A cell C is represented by a 1 when alive, or 0 when dead, in an m-by-m (or m×m) square array of cells. We calculate N - the sum of live cells in C's eight-location neighbourhood, then cell C is alive or dead in the next generation based on the following table: Assume cells beyond the boundary are always dead. The "game" is actually a zero-player game, meaning that its evolution is determined by its initial state, needing no input from human players. One interacts with the Game of Life by creating an initial configuration and observing how it evolves.
Although you should test your implementation on more complex examples such as the glider in a larger universe, show the action of the blinker (three adjoining cells in a row all alive), over three generations, in a 3 by 3 grid.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Conway's Game of Life step by step in the 11l programming language
Source code in the 11l programming language
V cellcountx = 6
V cellcounty = 5
V celltable = [(1, 2) = 1,
(1, 3) = 1,
(0, 3) = 1]
DefaultDict[(Int, Int), Int] universe
universe[(1, 1)] = 1
universe[(2, 1)] = 1
universe[(3, 1)] = 1
universe[(1, 4)] = 1
universe[(2, 4)] = 1
universe[(3, 4)] = 1
L(i) 4
print("\nGeneration "i‘:’)
L(row) 0 .< cellcounty
print(‘ ’(0 .< cellcountx).map(col -> [‘. ’, ‘O ’][:universe[(@row, col)]]).join(‘’))
DefaultDict[(Int, Int), Int] nextgeneration
L(row) 0 .< cellcounty
L(col) 0 .< cellcountx
nextgeneration[(row, col)] = celltable.get(
(universe[(row, col)],
-universe[(row, col)] + sum(multiloop(row-1..row+1,
col-1..col+1, (r, c) -> :universe[(r, c)]))
), 0)
universe = nextgeneration
V cellcountx = 6
V cellcounty = 5
V universe = [[0B] * cellcountx] * cellcounty
universe[1][1] = 1B
universe[2][1] = 1B
universe[3][1] = 1B
universe[1][4] = 1B
universe[2][4] = 1B
universe[3][4] = 1B
V nextgeneration = [[0B] * cellcountx] * cellcounty
L(i) 4
print("\nGeneration "i‘:’)
L(row) 0 .< cellcounty
print(‘ ’, end' ‘’)
L(col) 0 .< cellcountx
print(I universe[row][col] {‘O ’} E ‘. ’, end' ‘’)
print()
L(row) 0 .< cellcounty
L(col) 0 .< cellcountx
V s = 0
I row > 0
s = universe[row-1][col]
I col > 0
s += universe[row-1][col-1]
I col < cellcountx-1
s += universe[row-1][col+1]
I col > 0
s += universe[row][col-1]
I col < cellcountx-1
s += universe[row][col+1]
I row < cellcounty-1
s += universe[row+1][col]
I col > 0
s += universe[row+1][col-1]
I col < cellcountx-1
s += universe[row+1][col+1]
nextgeneration[row][col] = I universe[row][col] {s C 2..3} E s == 3
universe = nextgeneration
You may also check:How to resolve the algorithm Solve a Numbrix puzzle step by step in the Perl programming language
You may also check:How to resolve the algorithm Set puzzle step by step in the D programming language
You may also check:How to resolve the algorithm Pythagoras tree step by step in the J programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Ursala programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Rust programming language