cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A003324 A nonrepetitive sequence.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Let b(0) be the sequence 1,2,3,4. Proceeding by induction, let b(n) be a sequence of length 2^(n+2). Quarter b(n) into four blocks, A,B,C,D each of length 2^n, so that b(n) = ABCD. Then b(n+1) = ABCDADCB. [After Dean paper.] - Sean A. Irvine, Apr 20 2015

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Positions of 1's, 2's, 3's and 4's: A016813, A343500, A004767, A343501.
Cf. A292077.

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]