46
4
Imagine a "wire" that has n
spaces. Imagine further that there are "electrons" in that wire. These electrons only live for one unit of time. Any spaces in the wire that are adjacent to exactly one electron become an electron. In Game of Life terminology, this is B1/S
.
For example, this is a wire of length 10, with period 62.
Rules
- Input,
n
, is a single, positive integer. - Output must be a single integer denoting the period of a wire of length n.
- The starting state is a single electron at one end of the wire.
- The period does not necessarily include the starting state. Some lengths never return to the starting state, but all of them are periodic.
- A static wire (i.e., one without electrons) has period 1.
- Boundary conditions are not periodic. That is, the wire is not toroidal in any way.
Test cases
Special thanks to orlp for producing this list. (I have verified it up to n=27.)
1 1
2 2
3 1
4 6
5 4
6 14
7 1
8 14
9 12
10 62
11 8
12 126
13 28
14 30
15 1
16 30
17 28
18 1022
19 24
20 126
21 124
22 4094
23 16
24 2046
25 252
26 1022
27 56
28 32766
29 60
30 62
31 1
32 62
33 60
34 8190
35 56
36 174762
37 2044
38 8190
39 48
40 2046
41 252
42 254
43 248
44 8190
45 8188
You can see test cases for n=2 through 21 here with my Game-of-Life-esque simulator: Variations of Life.
EDIT: the sequence here has been published as A268754!
all of them are periodic And the period is upper-bounded by
2^n-1
, because that's the number of possible nonzero states of the "wire" – Luis Mendo – 2016-02-13T18:25:59.270@LuisMendo: Actually, the upper bound is less because electrons are never adjacent. Exactly how much less, I don't know. – El'endia Starman – 2016-02-13T19:31:48.627
The period does not necessarily include the starting state. Some lengths never return to the starting state, but all of them are periodic.
Do you have an example? – edc65 – 2016-02-13T21:52:14.307@edc65: A wire of length 5 is the smallest example. – El'endia Starman – 2016-02-13T22:00:00.583
@El'endiaStarman The upper bound is actually the Fibonacci numbers. (For length
n
, you'll either have an empty cell first, which means you can choose the remainingn-1
arbitrarily, which givess(n-1)
strings; or you'll start with a filled cell which means the next one has to be empty and you can then treat the remainingn-2
as a separate string. Sos(n) = s(n-1) + s(n-2)
. Ands(1) = 2
,s(2) = 3
.) – Martin Ender – 2016-02-14T15:27:19.487Of course the interesting question would be whether this bound can be brought down further based on the dynamics of the CA, since the sequence clearly grows much slower than the Fibonacci numbers. – Martin Ender – 2016-02-14T15:28:09.243
1More strongly, electrons alternate between odd and even positions, so the period is at most 2^(n/2+1). – xnor – 2016-02-15T03:19:34.750