Conway's Game of Life
Cellular automaton with simple rules creating complex patterns. Zero-player game. Turing complete. Famous for emergent behavior.
Visualization
Interactive visualization for Conway's Game of Life
Conway's Game of Life:
- • Cell: 2-3 neighbors → survives, else dies
- • Dead cell: exactly 3 neighbors → becomes alive
- • Zero-player game, Turing complete
- • Click cells to toggle. Press Step or Auto
Interactive visualization with step-by-step execution
Implementation
1class GameOfLife {
2 private grid: boolean[][];
3
4 constructor(width: number, height: number) {
5 this.grid = Array(height).fill(0).map(() => Array(width).fill(false));
6 }
7
8 nextGeneration(): void {
9 const newGrid = this.grid.map(row => [...row]);
10
11 for (let i = 0; i < this.grid.length; i++) {
12 for (let j = 0; j < this.grid[0].length; j++) {
13 const neighbors = this.countNeighbors(i, j);
14
15 if (this.grid[i][j]) {
16 // Cell is alive
17 newGrid[i][j] = neighbors === 2 || neighbors === 3;
18 } else {
19 // Cell is dead
20 newGrid[i][j] = neighbors === 3;
21 }
22 }
23 }
24
25 this.grid = newGrid;
26 }
27
28 private countNeighbors(row: number, col: number): number {
29 let count = 0;
30 for (let i = -1; i <= 1; i++) {
31 for (let j = -1; j <= 1; j++) {
32 if (i === 0 && j === 0) continue;
33 const r = row + i, c = col + j;
34 if (r >= 0 && r < this.grid.length && c >= 0 && c < this.grid[0].length) {
35 if (this.grid[r][c]) count++;
36 }
37 }
38 }
39 return count;
40 }
41}Deep Dive
Theoretical Foundation
Rules: 1) Live cell with 2-3 neighbors survives. 2) Live cell with <2 dies (underpopulation). 3) Live cell with >3 dies (overpopulation). 4) Dead cell with exactly 3 neighbors becomes alive (reproduction). Simple rules → complex emergent patterns.
Complexity
Time
O(w×h)
O(w×h)
O(w×h)
Space
O(w×h)
Applications
Industry Use
Modeling biological population dynamics
Studying emergence and self-organization
Computer graphics and procedural generation
Parallel computing algorithm testing
Artificial life research
Educational demonstrations of complexity
Screensavers and digital art
Use Cases
Related Algorithms
A* Search Algorithm
Informed search algorithm combining best-first search with Dijkstra's algorithm using heuristics. Widely used in pathfinding and graph traversal, A* is optimal and complete when using admissible heuristic. Used in games, GPS navigation, and robotics. Invented by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968.
Convex Hull (Graham Scan)
Find smallest convex polygon containing all points. Graham Scan invented by Ronald Graham in 1972, runs in O(n log n). Essential in computational geometry, computer graphics, and pattern recognition.
Line Segment Intersection
Determine if two line segments intersect. Fundamental geometric primitive used in graphics, CAD, GIS. Uses orientation and collinearity tests.
Caesar Cipher
The Caesar Cipher is one of the oldest and simplest encryption techniques, named after Julius Caesar who used it to protect military messages around 100 BC. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. For example, with a shift of 3, A becomes D, B becomes E, and so on. Despite being used for over 2000 years, it's extremely weak by modern standards with only 25 possible keys, making it trivially breakable by brute force or frequency analysis.