For hw2, you will be implementing an elementary cellular automaton, also known as Life 1D. A cellular automaton is composed of a space of cells, which can be dead or alive, and a rule describing the transition from one generation of cells to the next; each cell in the next generation depends on the 5 cells surrounding its position in the current generation. In Life 1D, the cells live in a 1-dimensional array.
Note: Some of you might be familiar with this game/assignment, but take notice that this version depends on 5 cells above it instead of 3.For example, here is an array of 7 cells. The value 7 was chosen arbitrarily for this example.
Cells are shaded if they are alive, otherwise they are dead. Therefore, only the center cell in this example is alive (Your initial row will look similar no matter how long it is; only the center cell starts out alive).
We produce the next generation of cells
using a rule that ranges from 0-4294967295. Note that such a number can be represented with 32 bits.
For our example, we will consider the rule 3141592653, which is equal to 0b10111011010000001110011001001101.
Each bit in this binary number corresponds to whether the child cell of the pattern representing its position will be dead or alive.
Position (decimal) | Position (binary) | Dead/Alive |
0 | 0b00000 | 1 |
1 | 0b00001 | 0 |
2 | 0b00010 | 1 |
3 | 0b00011 | 1 |
4 | 0b00100 | 0 |
5 | 000b101 | 0 |
6 | 0b00110 | 1 |
7 | 0b00111 | 0 |
and | so | on... |
30 | 0b11110 | 0 |
31 | 0b11111 | 1 |
rows
and rule
. The rows
value
determines the size of the picture, which will be (rows
+1) high and
(2*rows
+1) wide. The first row consists of all dead cells except the center cell, which is alive. Note that since the number of columns is always odd, there's always a definite center.
We use rows
+1 because rows
really refers to the number of generated rows, which doesn't include the aforementioned initial row.
which supports the following:
Usage: Life1D <rows> <rule> This program simulates 1D Life: the simplest class of one-dimensional cellular automata in a <ROWS=rows+1> x <COLS=2*rows+1> grid starting with a single live cell in the middle of the top row using rule <rule>. These 1D rules are defined in Wolfram's Elementary Cellular Automata: http://mathworld.wolfram.com/ElementaryCellularAutomaton.html This program will print to stdout data in plain PBM file format. This output can be easily viewed using the display command or converted to a another format using the pbmto* and ppmto* utilities. A plain ascii PBM file can be created by adding a header line "P1 <WIDTH> <HEIGHT>" and followed by a grid of data (0 = dead = white, 1 = live = black). Add a comment on the first line with a brief description of the image. Arguments: <rows> is a positive integer specifying the number of rows to generate (not counting the first "seed row" which is all dead except for a central live cell). The columns are computed automatically -- enough so that the rule, if it were to grow in the normal triangular pattern, would just perfectly reach the edge. Off the board is considerered "dead". <rule> is a number from 0-4294967295 specifying the rule to use.
unix% ./Life1D 3 58979 P1 7 4 ## 3 rows of Life1D (Rule 58979) by Yourfirstname Yourlastname 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0
unix% ./Life1D 5 32384626 P1 11 6 ## 5 rows of Life1D (Rule 32384626) by Yourfirstname Yourlastname 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
unix% ./Life1D 4 4338327 P1 9 5 ## 4 rows of Life1D (Rule 4338327) by Yourfirstname Yourlastname 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0
unix% ./Life1D 17 3141592653 P1 35 18 ## 17 rows of Life1D (Rule 3141592653) by Yourfirstname Yourlastname 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 0 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 1 0
P1 [a] [b] ## [c] rows of Life1D (Rule [d]) by [e]where [a] is the number of displayed cols, [b] is the number of displayed rows, [c] is the <row> parameter. [d] is the <rule> parameter, [e] is YOUR name
000010000 000010100 000010010and this is valid:
0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0
unix% ./Life1D 3 58979 | ppmtogif > Life1D_3_60.gifHere are the gifs resulting from the examples above:
Life1D 3 58979 | Life1D 5 32384626 | Life1D 4 4338327 |