17
2
Background
The Random Domino Automaton is a toy model for earthquakes, inspired by cellular automata. In this challenge, your task is to simulate a simplified version of this model, and collect data out of it.
The automaton is defined on an array A
of k
bits, representing a fault line on which earthquakes may occur.
The array wraps around at its borders.
The condition A[i] = 0
means that position i
is relaxed, and A[i] = 1
means that it's excited, or contains stored energy.
At each time step, one position of the array is chosen uniformly at random.
If that position is relaxed, it becomes excited (potential energy is added to the system).
If that position is already excited, it triggers an earthquake, and the chosen position and all excited positions connected to it are relaxed again.
The number of excited positions that become relaxed is the magnitude of the earthquake.
Example
Consider the array
100101110111
of length 12. If the random process chooses the second bit from the left, the array is updated to
110101110111
^
since the chosen bit (marked with ^
) was 0
.
If we next choose the fourth bit from the left, which is an isolated 1
, an eartquake of magnitude 1 is triggered, and the bit is set to 0
again:
110001110111
^
Next, we might choose the second bit from the right, which triggers an earthquake of magnitude 5:
000001110000
^
Note that all 1
s in the same "cluster" as the chosen one were part of the quake, and the array wraps around at the border.
The Task
You shall take as inputs two positive integers k
and t
, and your task is to simulate the random domino automaton for t
time steps, starting from an initial length-k
array of all 0
s.
Your output shall be a list L
of k
integers, where L[i]
(with 1-based indexing) contains the number of earthquakes of magnitude i
that occurred during the simulation.
You are allowed to drop trailing zeroes from the output.
For the inputs k = 15
and t = 1000
, some representative outputs are
[117, 97, 45, 26, 10, 5, 3, 1, 3, 0, 0, 0, 0, 0, 0]
[135, 91, 58, 21, 8, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0]
[142, 63, 51, 31, 17, 4, 2, 1, 1, 0, 0, 0, 0, 0, 0]
[106, 75, 45, 30, 16, 8, 5, 2, 2, 0, 0, 0, 0, 0, 0]
[111, 96, 61, 22, 3, 8, 3, 2, 0, 0, 0, 1, 0, 0, 0]
Rules
Both full programs and functions are allowed. The shortest byte count wins, and standard loopholes are disallowed.
Note that you are not required to simulate the automaton using any particular implementation, only the output matters.
2Is it possible that you can add a caret ^ under the bit that changes? It might make it easier to visualize the example – DeadChex – 2015-06-23T16:04:27.987
1@DeadChex Good idea, updated. – Zgarb – 2015-06-23T16:07:22.290