14
1
Introduction
In this challenge, we will simulate a certain probabilistic cellular automaton using very bad pseudorandom numbers.
The cellular automaton is defined on binary strings by the following local rule.
Suppose that the left neighbor of a cell and the cell itself have states a
and b
.
- If
min(a,b) == 0
, then the new state ofb
ismax(a,b)
. - If
min(a,b) == 1
, then the new state ofb
is chosen randomly from{0,1}
.
The following picture shows one possible 10-step evolution of a single 1
.
1
11
101
1111
11001
101011
1111111
10001001
110011011
1010111101
Note how two adjacent 1
s sometimes evolve to 1
, and sometimes to 0
, and the border-most bits are always 1
s.
Your task is to produce a cellular automaton evolution of this form.
Inputs
Your inputs are a positive integer n
, denoting the number of rows to display, and a non-empty list of bits L
, which we use as a source of randomness.
Output
Your output is a list of lists or 2D array of bits, depicting the evolution of a single 1
for n
time steps, as in the above figure.
You can pad the output with 0
s to get rows of equal lengths, if desired, but there must not be leading 0
s.
The random choices in the cellular automaton must be drawn from the list L
, jumping back to the beginning when it is exhausted.
More explicitly, if the output is traversed one row at a time form top to bottom, left to right, then the successive random choices shall form the list L
repeated as many times as necessary.
Example
Suppose the inputs are n = 7
and L = [0,1,0]
.
Then the cellular automaton evolves as follows during the 7 steps, where we have put a v
right above every random choice:
[1]
[1,1]
v
[1,0,1]
[1,1,1,1]
v v v
[1,1,0,0,1]
v
[1,1,1,0,1,1]
v v v
[1,0,0,1,1,1,1]
If we read all the bits marked with a v
, we get 01001001
, which is L
repeated 2.66 times.
The next random bit would be 0
.
Rules and Scoring
You can write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed. The exact format of the inputs and outputs is unimportant (within reason).
Test Cases
Deterministic version, every random bit is 0
:
Inputs: 10 [0]
Output:
1
11
101
1111
10001
110011
1010101
11111111
100000001
1100000011
Every random bit is 1
:
Inputs: 6 [1,1]
Output:
1
11
111
1111
11111
111111
Pseudorandom versions:
Inputs: 10 [0,0,1]
Output:
1
11
101
1111
10101
111111
1010011
11110101
101011111
1111101001
Inputs: 10 [1,0,0,1]
Output:
1
11
111
1001
11011
111111
1001101
11010111
111111101
1011001111
Inputs: 15 [1,1,1,0,0,0]
Output:
1
11
111
1111
10001
110011
1110111
11011001
111111011
1100011111
11100100011
111101100101
1001111101111
11011000111111
101101001011101
1My apologies if I don't understand the challenge correctly, but can't you replace
min(a,b)
witha+b>1
andmax(a,b)
witha+b
? I realize you'd probably have to do something to handle the very first case of1
->11
(I think you could doL=[1]+f()...
, or find some way to insert 1 in the front ofL
because that would always pop 1 for the second line) – cole – 2015-10-05T00:02:42.110@Cole Luckily no changes have to be made to the rest of the program as the changes only affect the way of knowing the min and max values of a pair of bits. – Ioannes – 2015-10-05T00:27:09.363
1You missed that you can remove a space here:
r[x-1]&r[x] else
:) – Kade – 2015-10-05T01:55:50.600Would n*2 -> nn work? – lirtosiast – 2015-10-06T02:19:04.343
@Thomas You're right! – Ioannes – 2015-10-06T07:05:44.967