A Simple Design Method #
Most interesting problems reward careful thought before we start coding.
A few questions to consider:
- What data (entities, state, input parameters) do we need to represent?
- What operations do we need to perform on those data?
- How might we represent those data to support those operations?
- How do we arrange those operations to find a solution?
- What output or interface do we need to support?
- What are the objectives, constraints, and environment under which we are working?
- How might we need/want to generalize or modify the problem and how do our answers to these questions change when we do?
Aphorism of the day: Make it run, make it right, make it fast – in that order
Cellular Automata #
A cellular automaton is a discrete model of computation that can exhibit complex structure from simple rules. The consist of a regular lattice of cells each in one of a finite number of states. The states of the cells evolve according to simple rules.
A famous example is Conway’s Game of Life.
- The automaton evolves on a rectangular grid.
- Each cell has two states, on or off.
- The next state of a cell is determined by how many living neighbors it has, where the neighborhood contains the eight cells surrounding the cell.
- A live cell with
- Fewer than 2 live neighbors, dies (underpopulation)
- More than 3 live neighbors, dies (overpopulation)
- 2-3 live neighbors, survives.
- A dead cell with exactly three live neighbors is born (reproduction)
This rule set is sometimes denoted B3/S23
. This is called
an outer totalistic rule set because the next generation
at a cell depends only on (a) the state at that cell, and
(b) the total value of the cell’s neighbors.
Some online simulations:
Our Task #
Simulate the game of life. We will focus on computing the state at a given time and outputing that state, rather than simulating the system dynamically and graphically.
Design Discussion #
Let’s try to answer the seven questions.
What data (entities, state, input parameters) do we need to represent? #
What operations do we need to perform on those data? #
How might we represent those data to support those operations? #
How do we arrange those operations to find a solution? #
What output or interface do we need to support? #
What are the objectives, constraints, and environment under which we are working? #
How might we need/want to generalize or modify the problem and how do our answers to these questions change when we do? #
Pair Programming Task #
Ultimate goal is to write a script automaton
that simulates the Game of Life (and perhaps other automata)
for a fixed amount of time. The script should:
- Accept an initial state as input
- Produce an output format to show the requested state
- Support our standard
--help
and--version
options - Have an option for producing output in the same format as the program’s input
- Options for variations?
Today we will on the core computations. Split into common language pairs (generally).
- Devise a representation of the state
- Write a function that updates the state by one (or more if desired) steps
- Write (critical) or stub (generic) support functions
Layout some tests that your main function should satisfy.