A003324 A nonrepetitive sequence.
1, 2, 3, 4, 1, 4, 3, 2, 1, 2, 3, 2, 1, 4, 3, 4, 1, 2, 3, 4, 1, 4, 3, 4, 1, 2, 3, 2, 1, 4, 3, 2, 1, 2, 3, 4, 1, 4, 3, 2, 1, 2, 3, 2, 1, 4, 3, 2, 1, 2, 3, 4, 1, 4, 3, 4, 1, 2, 3, 2, 1, 4, 3, 4, 1, 2, 3, 4, 1
Offset: 1
References
- N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
Links
- Sean A. Irvine, Table of n, a(n) for n = 1..10000
- Richard A. Dean, A sequence without repeats on x, x^{-1}, y, y^{-1}, Amer. Math. Monthly 72, 1965. pp. 383-385. MR 31 #350.
- Françoise Dejean, Sur un Théorème de Thue, J. Combinatorial Theory, vol. 13 A, iss. 1 (1972) 90-99.
- N. J. A. Sloane, P. Flor, L. F. Meyers, G. A. Hedlund. M. Gardner, Collection of documents and notes related to A1285, A3270, A3324
- Jianing Song, Proof for my formula for A003324
Programs
-
Mathematica
b[0] = Range[4]; b[n_] := b[n] = Module[{aa, bb, cc, dd}, {aa, bb, cc, dd} = Partition[b[n - 1], 2^(n-1)]; Join[aa, bb, cc, dd, aa, dd, cc, bb] // Flatten]; b[5] (* Jean-François Alcover, Sep 27 2017 *) a[n_] := If[OddQ[n], Mod[n, 4], Module[{e = IntegerExponent[n, 2], k}, k = (n/2^e - 1)/2; If[OddQ[k + e], 2, 4]]]; Array[a, 100] (* Jean-François Alcover, Apr 19 2021, after Jianing Song *)
-
PARI
a(n) = if(n%2, n%4, my(e=valuation(n,2), k=bittest(n, e+1)); if((k+e)%2, 2, 4)) \\ Jianing Song, Apr 15 2021
-
Python
def A003324(n): return n&3 if n&1 else 2<<(((n>>(m:=(~n&n-1).bit_length()))+1>>1)+m&1) # Chai Wah Wu, Feb 26 2025
Formula
a(n) = n mod 4 for odd n; for even n, write n = (2*k+1) * 2^e, then a(n) = 2 if k+e is odd, 4 if k+e is even. - Jianing Song, Apr 15 2021
Conjecture: a(2*n) = (A292077(n)+1)*2. Confirmed for first 1000 terms. - John Keith, Apr 18 2021 [This conjecture is correct. Write n = (2*k+1) * 2^e. If k+e is even, then we have A292077(n) = 0 and a(2n) = 2; if k+e is odd, then we have A292077(n) = 1 and a(2n) = 4. - Jianing Song, Nov 27 2021]
Comments