The Challenge
You are to write a complete program that takes seven numbers from STDIN, and prints the two dimensional history of the cellular automaton (CA) to STDOUT. This is code golf.
Input Formatting The input will be seven integers/strings separated by commas. The first number is the number of the rule according to Wolfram code (the standard name for each rule). The second is the initial starting configuration. The third and fourth describe what pattern and how many times it should be appended to the left of the starting config. as padding. The fifth and sixth do the same for the right side. The last number is the number of generations to run the simulation.
So, an example of input is 90,11,0,4,0,4,5
. This should tell your program that you are running rule 90. It should also tell the program that you want the initial configuration to be 11
with the string 0
appended 4 times to both ends, so the actual starting pattern is 0000110000
. It also tells your program to run this simulation for 5 generations.
Output Your program should print the entire array of cells each generation (separated by newlines), so that the output is the space-time diagram of the CA. For each generation, the state of each cell is determined by its state and the states of the cells to the immediate left and right, in accordance to the rule provided as input. The simulation should wrap around the edges. The first thing printed should be the starting array as gen. 0.
The input 90,11,0,4,0,4,5
should result in the following output as exactly as possible.
0000110000
0001111000
0011001100
0111111110
1100000011
0110000110
Notice that the starting state is not included in the five generations. Also notice that the simulation wraps around the edges.
More Examples
input:
184,1100,01,2,01,1,4
output:
0101110001
1011101000
0111010100
0110101010
0101010101
input:
0,1011,1,0,0,1,2
output:
10110
00000
00000
More information on how 1D CA's work and how they are numbered