# Wolfram Language™

Open live version

## Implement Conway’s Game of Life

Conways Game Of Life, in three lines of code.

### code

gameOfLife = {224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}}; board = RandomInteger[1, {50, 50}]; Dynamic[ArrayPlot[ board = Last[CellularAutomaton[gameOfLife, board, {{0, 1}}]]]]

Show the development over time of the average slice of a Game of Life board:

ArrayPlot[ Mean /@ CellularAutomaton[gameOfLife, RandomInteger[1, {10, 400}], 300]]

### how it works

Implementing a complete, dynamic Game of Life in the Wolfram Language requires three lines of code:

gameOfLife = {224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}}; board = RandomInteger[1, {50, 50}]; Dynamic[ArrayPlot[ board = Last[CellularAutomaton[gameOfLife, board, {{0, 1}}]]]]

The first line defines the rules of the Game of Life in the format used by the CellularAutomaton function. The second line sets up a 50×50 board of random zeros and ones. The third line runs the game and plots the developing board.

This expressionfrom Stephen Wolframs video Introduction to the Wolfram Languageshows the development over time of the average slice of a Game of Life board.

ArrayPlot[ Mean /@ CellularAutomaton[gameOfLife, RandomInteger[1, {10, 400}], 300]]