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.

Showing 1-6 of 6 results.

A000002 Kolakoski sequence: a(n) is length of n-th run; a(1) = 1; sequence consists just of 1's and 2's.

Original entry on oeis.org

1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2
Offset: 1

Views

Author

Keywords

Comments

Historical note: the sequence might be better called the Oldenburger-Kolakoski sequence, since it was discussed by Rufus Oldenburger in 1939; see links. - Clark Kimberling, Dec 06 2012. However, to avoid confusion, this sequence will be known in the OEIS as the Kolakoski sequence. It is undesirable to have some entries refer to the Oldenburger-Kolakoski sequence and others to the Kolakoski sequence. - N. J. A. Sloane, Nov 22 2017
It is an unsolved problem to show that the density of 1's is equal to 1/2.
A weaker problem is to construct a combinatorial bijection between the set of positions of 1's and the set of positions of 2's. - Gus Wiseman, Mar 01 2016
The sequence is cubefree and all square subwords have lengths which are one of 2, 4, 6, 18 and 54 (see A294447) [Carpi, 1994].
This is a fractal sequence: replace each run with its length and recover the original sequence. - Kerry Mitchell, Dec 08 2005
Kupin and Rowland write: We use a method of Goulden and Jackson to bound freq_1(K), the limiting frequency of 1 in the Kolakoski word K. We prove that |freq_1(K) - 1/2| <= 17/762, assuming the limit exists and establish the semirigorous bound |freq_1(K) - 1/2| <= 1/46. - Jonathan Vos Post, Sep 16 2008
freq_1(K) is conjectured to be 1/2 + O(log(K)) (see PlanetMath link). - Jon Perry, Oct 29 2014
Conjecture: Taking the sequence in word lengths of 10, for example, batch 1-10, 11-20, etc., then there can only be 4, 5 or 6 1's in each batch. - Jon Perry, Sep 26 2012
From Jean-Christophe Hervé, Oct 04 2014: (Start)
The sequence does not contain words of the form ababa, because this would imply the impossible 111 (1 b, 1 a, 1 b) somewhere before. This demonstrates the conjecture made by Jon Perry: more than 6 1's or 6 2's in a word of 10 would necessitate something like aabaabaaba, which would imply the impossible 12121 before (word aabaababaa is also impossible because of ababa). The remark on the sextuplets below even shows that the number of 1's in any 9-tuplet is always 4 or 5.
There are only 6 triples that appear in the sequence (112, 121, 122, 211, 212 and 221); and by the preceding argument, only 18 sextuplets: the 6 double triples (112112, etc.); 112122, 112212, 121122, 121221, 211212, and 211221; and those obtained by reversing the order of the triples (122112, etc.). Regarding the density of 1's in the sequence, these 12 sextuplets all have a density 1/2 of 1's, and the 6 double triples all lead to a word with this exact density after transformation by the Kolakoski rules, for example: 112112 -> 12112122 (4 1's/8); this is because the second triple reverses the numbers of 1's and 2's generated by the first triple. Therefore, the sequence can be split into the double triples on one side, a part whose transformation (which is in the sequence) has a density of 1's of 1/2; and a part with the other sextuplets, which has directly the same density of 1's. (End)
If we map 1 to +1 and 2 to -1, then the mapped sequence would have a [conjectured] mean of 0, since the Kolakoski sequence is [conjectured] to have an equal density (1/2) of 1s and 2s. For the partial sums of this mapped sequence, see A088568. - Daniel Forgues, Jul 08 2015
Looking at the plot for A088568, it seems that although the asymptotic densities of 1s and 2s appear to be 1/2, there might be a bias in favor of the 2s. I.e., D(1) = 1/2 - O(log(n)/n), D(2) = 1/2 + O(log(n)/n). - Daniel Forgues, Jul 11 2015
From Michel Dekking, Jan 31 2018: (Start)
(a(n)) is the unique fixed point of the 2-block substitution beta
11 -> 12
12 -> 122
21 -> 112
22 -> 1122.
A 2-block substitution beta maps a word w(1)...w(2n) to the word
beta(w(1)w(2))...beta(w(2n-1)w(2n)).
If the word has odd length, then the last letter is ignored.
It was noted by me in 1979 in the Bordeaux seminar on number theory that (a(n+1)) is fixed point of the 2-block substitution 11 -> 21, 12 -> 211, 21 -> 221, 22 -> 2211. (End)
Named after the American artist and recreational mathematician William George Kolakoski (1944-1997). - Amiram Eldar, Jun 17 2021

Examples

			Start with a(1) = 1. By definition of the sequence, this says that the first run has length 1, so it must be a single 1, and a(2) = 2. Thus, the second run (which starts with this 2) must have length 2, so the third term must be also be a(3) = 2, and the fourth term can't be a 2, so must be a(4) = 1. Since a(3) = 2, the third run must have length 2, so we deduce a(5) = 1, a(6) = 2, and so on. The correction I made was to change a(4) to a(5) and a(5) to a(6). - _Labos Elemer_, corrected by _Graeme McRae_
		

References

  • Jean-Paul Allouche and Jeffrey Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, p. 337.
  • Éric Angelini, "Jeux de suites", in Dossier Pour La Science, pp. 32-35, Volume 59 (Jeux math'), April/June 2008, Paris.
  • F. M. Dekking, What Is the Long Range Order in the Kolakoski Sequence?, in The mathematics of long-range aperiodic order (Waterloo, ON, 1995), 115-125, NATO Adv. Sci. Inst. Ser. C Math. Phys. Sci., 489, Kluwer Acad. Publ., Dordrecht, 1997. Math. Rev. 98g:11022.
  • Michael S. Keane, Ergodic theory and subshifts of finite type, Chap. 2 of T. Bedford et al., eds., Ergodic Theory, Symbolic Dynamics and Hyperbolic Spaces, Oxford, 1991, esp. p. 50.
  • J. C. Lagarias, Number Theory and Dynamical Systems, pp. 35-72 of S. A. Burr, ed., The Unreasonable Effectiveness of Number Theory, Proc. Sympos. Appl. Math., 46 (1992). Amer. Math. Soc.
  • Michel Rigo, Formal Languages, Automata and Numeration Systems, 2 vols., Wiley, 2014. Mentions this sequence - see "List of Sequences" in Vol. 2.
  • N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • Ilan Vardi, Computational Recreations in Mathematica. Addison-Wesley, Redwood City, CA, 1991, p. 233.

Crossrefs

Cf. A054354, bisections: A100428, A100429.
Cf. A013947, A156077, A234322 (positions, running total and percentage of 1's).
Cf. A118270.
Cf. A049705, A088569 (are either subsequences of A000002? - Jon Perry, Oct 30 2014)
Kolakoski-type sequences using other seeds than (1,2):
A078880 (2,1), A064353 (1,3), A071820 (2,3), A074804 (3,2), A071907 (1,4), A071928 (2,4), A071942 (3,4), A074803 (4,2), A079729 (1,2,3), A079730 (1,2,3,4).
Other self-describing: A001462 (Golomb sequence, see also references therein), A005041, A100144.
Cf. A088568 (partial sums of [3 - 2 * a(n)]).

Programs

  • Haskell
    a = 1:2: drop 2 (concat . zipWith replicate a . cycle $ [1,2]) -- John Tromp, Apr 09 2011
    
  • Maple
    M := 100; s := [ 1,2,2 ]; for n from 3 to M do for i from 1 to s[ n ] do s := [ op(s),1+((n-1)mod 2) ]; od: od: s; A000002 := n->s[n];
    # alternative implementation based on the Cloitre formula:
    A000002 := proc(n)
        local ksu,k ;
        option remember;
        if n = 1 then
            1;
        elif n <=3 then
            2;
        else
            for k from 1 do
                ksu := add(procname(i),i=1..k) ;
                if n = ksu then
                    return (3+(-1)^k)/2 ;
                elif n = ksu+ 1 then
                    return (3-(-1)^k)/2 ;
                end if;
            end do:
        end if;
    end proc: # R. J. Mathar, Nov 15 2014
  • Mathematica
    a[steps_] := Module[{a = {1, 2, 2}}, Do[a = Append[a, 1 + Mod[(n - 1), 2]], {n, 3, steps}, {i, a[[n]]}]; a]
    a[ n_] := If[ n < 3, Max[ 0, n], Module[ {an = {1, 2, 2}, m = 3}, While[ Length[ an] < n, an = Join[ an, Table[ Mod[m, 2, 1], { an[[ m]]} ]]; m++]; an[[n]]]] (* Michael Somos, Jul 11 2011 *)
    n=8; Prepend[ Nest[ Flatten[ Partition[#, 2] /. {{2, 2} -> {2, 2, 1, 1}, {2, 1} -> {2, 2, 1}, {1, 2} -> {2, 1, 1}, {1, 1} -> {2, 1}}] &, {2, 2}, n], 1] (* Birkas Gyorgy, Jul 10 2012 *)
    KolakoskiSeq[n_Integer] := Block[{a = {1, 2, 2}}, Fold[Join[#1, ConstantArray[Mod[#2, 2, 1], #1[[#2]]]] &, a, Range[3, n]]]; KolakoskiSeq[999] (* Mikk Heidemaa, Nov 01 2024 *) (* Corrected by Giorgos Kalogeropoulos, May 09 2025 *)
  • PARI
    my(a=[1,2,2]); for(n=3,80, for(i=1,a[n],a=concat(a,2-n%2))); a
    
  • PARI
    {a(n) = local(an=[1, 2, 2], m=3); if( n<1, 0, while( #an < n, an = concat( an, vector(an[m], i, 2-m%2)); m++); an[n])};
    
  • Python
    # For explanation see link.
    def Kolakoski():
        x = y = -1
        while True:
            yield [2,1][x&1]
            f = y &~ (y+1)
            x ^= f
            y = (y+1) | (f & (x>>1))
    K = Kolakoski()
    print([next(K) for  in range(100)]) # _David Eppstein, Oct 15 2016

Formula

These two formulas define completely the sequence: a(1)=1, a(2)=2, a(a(1) + a(2) + ... + a(k)) = (3 + (-1)^k)/2 and a(a(1) + a(2) + ... + a(k) + 1) = (3 - (-1)^k)/2. - Benoit Cloitre, Oct 06 2003
a(n+2)*a(n+1)*a(n)/2 = a(n+2) + a(n+1) + a(n) - 3 (this formula doesn't define the sequence, it is just a consequence of the definition). - Benoit Cloitre, Nov 17 2003
a(n+1) = 3 - a(n) + (a(n) - a(n-1))*(a(b(n)) - 1), where b(n) is the sequence A156253. - Jean-Marc Fedou and Gabriele Fici, Mar 18 2010
a(n) = (3 + (-1)^A156253(n))/2. - Benoit Cloitre, Sep 17 2013
Conjectures from Boštjan Gec, Oct 07 2024: (Start)
a(n)*(a(n-1) + a(n-2) - 3) + a(n-1)*a(n-2) + 7 = 3*a(n-1) + 3*a(n-2).
a(n)*(a(n-1) + a(n-2) - 3) = a(n-3)*(a(n-1) + a(n-2) - 3). (End)
Comment from Kevin Ryde, Oct 07 2024: The above formulas are true: The parts identify when terms are same or different and they hold for any sequence of 1's and 2's with run lengths 1 or 2.

Extensions

Minor edits to example and PARI code made by M. F. Hasler, May 07 2014

A054354 First differences of Kolakoski sequence A000002.

Original entry on oeis.org

1, 0, -1, 0, 1, -1, 1, 0, -1, 1, 0, -1, 0, 1, -1, 0, 1, 0, -1, 1, -1, 0, 1, -1, 1, 0, -1, 0, 1, -1, 0, 1, -1, 1, 0, -1, 1, 0, -1, 0, 1, -1, 1, 0, -1, 1, -1, 0, 1, -1, 0, 1, 0, -1, 1, 0, -1, 0, 1, -1, 1, 0, -1, 1, 0, -1, 0, 1, -1, 0, 1, -1, 1, 0, -1, 1, -1, 0, 1, 0, -1, 1, 0, -1, 0, 1, -1, 1, 0, -1, 1, 0, -1
Offset: 1

Views

Author

N. J. A. Sloane, May 07 2000

Keywords

Comments

The Kolakoski sequence has only 1's and 2's, and is cubefree. Thus, for all n>=1, a(n) is in {-1, 0, 1}, a(n+1) != a(n), and if a(n) = 0, a(n+1) = -a(n-1), while if a(n) != 0, either a(n+1) = 0 and a(n+2) = -a(n) or a(n+1) = -a(n). A further consequence is that the maximum gap between equal values is 4: for all n, there is an integer k, 1Jean-Christophe Hervé, Oct 05 2014
From Daniel Forgues, Jul 07 2015: (Start)
Second differences: {-1, -1, 1, 1, -2, 2, -1, -1, 2, -1, -1, 1, 1, ...}
The sequence of first differences bounces between -1 and 1 with a slope whose absolute value is either 1 or 2. We can compress the information in the second differences into {-1, 1, -2, 2, -1, 2, -1, 1, ...} since the -1 and the 1 come in pairs; which can be compressed further into {1, 1, 2, 2, 1, 2, 1, 1, ...} since the signs alternate, where we only need to know that the initial sign is negative. (End)
This appears to divide the positive integers into three sets, each with density approaching 1/3. Note there are no adjacent equal parts (as mentioned above). - Gus Wiseman, Oct 10 2024

Crossrefs

Positions of 0 are A078649.
For Golomb's sequence (A001462) we have A088517.
Positions of -1 are A156242 (descents).
Positions of 1 are A156243 (ascents).
First differences (or second differences of A000002) are A376604.
The Kolakoski sequence (A000002):
- Statistics: A074286, A088568, A156077, A156253.
- Transformations: A054354, A156728, A306323, A332273, A332875, A333229.
Cf. A333254.

Programs

  • Haskell
    a054354 n = a054354_list !! (n-1)
    a054354_list = zipWith (-) (tail a000002_list) a000002_list
    -- Reinhard Zumkeller, Aug 03 2013
  • Mathematica
    a2 = {1, 2, 2}; Do[ a2 = Join[a2, {1 + Mod[n - 1, 2]}], {n, 3, 70}, {a2[[n]]}]; Differences[a2] (* Jean-François Alcover, Jun 18 2013 *)

Formula

Abs(a(n)) = (A000002(n)+A000002(n+1)) mod 2. - Benoit Cloitre, Nov 17 2003

A376604 Second differences of the Kolakoski sequence (A000002). First differences of A054354.

Original entry on oeis.org

-1, -1, 1, 1, -2, 2, -1, -1, 2, -1, -1, 1, 1, -2, 1, 1, -1, -1, 2, -2, 1, 1, -2, 2, -1, -1, 1, 1, -2, 1, 1, -2, 2, -1, -1, 2, -1, -1, 1, 1, -2, 2, -1, -1, 2, -2, 1, 1, -2, 1, 1, -1, -1, 2, -1, -1, 1, 1, -2, 2, -1, -1, 2, -1, -1, 1, 1, -2, 1, 1, -2, 2, -1, -1
Offset: 1

Views

Author

Gus Wiseman, Oct 02 2024

Keywords

Comments

Since A000002 has no runs of length 3, this sequence contains no zeros.
The densities appear to approach (1/3, 1/3, 1/6, 1/6).

Examples

			The Kolakoski sequence (A000002) is:
  1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, ...
with first differences (A054354):
  1, 0, -1, 0, 1, -1, 1, 0, -1, 1, 0, -1, 0, 1, -1, 0, 1, 0, -1, 1, -1, 0, 1, -1, ...
with first differences (A376604):
  -1, -1, 1, 1, -2, 2, -1, -1, 2, -1, -1, 1, 1, -2, 1, 1, -1, -1, 2, -2, 1, 1, -2, ...
		

Crossrefs

A001462 is Golomb's sequence.
A078649 appears to be zeros of the first and third differences.
A288605 gives positions of first appearances of each balance.
A306323 gives a 'broken' version.
A333254 lists run-lengths of differences between consecutive primes.
For the Kolakoski sequence (A000002):
- Restrictions: A074264, A100428, A100429, A156263, A156264.
- Transformations: A054354, A156728, A332273, A332875, A333229, A376604.
For second differences: A036263 (prime), A073445 (composite), A376559 (perfect-power), A376562 (non-perfect-power), A376590 (squarefree), A376593 (nonsquarefree), A376596 (prime-power), A376599 (non-prime-power).

Programs

  • Mathematica
    kolagrow[q_]:=If[Length[q]<2,Take[{1,2},Length[q]+1],Append[q,Switch[{q[[Length[Split[q]]]],q[[-2]],Last[q]},{1,1,2},1,{1,2,1},2,{2,1,1},2,{2,1,2},2,{2,2,1},1,{2,2,2},1]]]
    kol[n_]:=Nest[kolagrow,{1},n-1];
    Differences[kol[100],2]

A100428 Bisection of Kolakoski sequence A000002.

Original entry on oeis.org

1, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1
Offset: 1

Views

Author

N. J. A. Sloane, Nov 20 2004

Keywords

Comments

Lengths of runs of ones in A000002. - Reinhard Zumkeller, Aug 03 2013
As in the Kolakoski sequence itself, the length of runs in this sequence is 1 or 2 : a run X,X,X is not possible, since it would imply X,Y,X,Y,X in the Kolakoski sequence, which in turn would imply 1, 1, 1 somewhere before (one Y, one X, one Y) which is not possible. - Jean-Christophe Hervé, Oct 04 2014

Crossrefs

Programs

  • Haskell
    a100428 n = a100428_list !! n
    a100428_list = f a000002_list where f (u:_:us) = u : f us
    -- Reinhard Zumkeller, Aug 03 2013

Extensions

More terms from Joshua Zucker, May 12 2006
Offset changed by Reinhard Zumkeller, Aug 03 2013

A216345 Position of the beginning of the n-th run in A000002.

Original entry on oeis.org

1, 2, 4, 6, 7, 8, 10, 11, 13, 15, 16, 18, 20, 21, 22, 24, 25, 26, 28, 30, 31, 33, 34, 35, 37, 38, 40, 42, 43, 44, 46, 47, 48, 50, 51, 53, 55, 56, 58, 60, 61, 62, 64, 65, 67, 69, 70, 72, 73, 74, 76, 77, 78, 80, 82, 83, 85, 87, 88, 89, 91, 92, 94, 96, 97, 99, 101, 102, 103
Offset: 1

Views

Author

Jon Perry, Sep 04 2012

Keywords

Comments

If n is odd then the run is 1's, otherwise it's 2's.

Examples

			Kolakoski sequence starts 1221121 so we can see that this sequence begins 1,2,4,6,7.
		

Crossrefs

Programs

  • Haskell
    a216345 n = a216345_list !! (n-1)
    a216345_list = 1 : (filter (\x -> a000002 x /= a000002 (x - 1)) [2..])
    -- Reinhard Zumkeller, Aug 03 2013
  • JavaScript
    a=new Array();
    a[1]=1;  a[2]=2;  a[3]=2;
    cd=1;  ap=3;
    for (i=4; i<50; i++)
    {
        if (a[ap]==1) a[i]=cd;
        else {a[i]=cd; a[i+1]=cd; i++}
        ap++;
        cd=3-cd;
    }
    /* document.write(a); document.write("
    "); */ b=new Array(); b[1]=1; c=2; for (i=2; i<50; i++) if (a[i]!=a[i-1]) b[c++]=i; document.write(b);

Formula

{n: A156728(n-1)=1}. - R. J. Mathar, Sep 14 2012
a(n+1) = A054353(n)+1 = a(n) + A000002(n). - Jean-Christophe Hervé, Oct 05 2014

A248806 Number of 2's separating successive 1's in the Kolakoski sequence A000002.

Original entry on oeis.org

2, 0, 1, 2, 2, 0, 1, 0, 2, 1, 0, 1, 2, 0, 1, 0, 1, 2, 2, 0, 1, 2, 1, 0, 1, 0, 2, 2, 0, 1, 2, 2, 0, 1, 0, 1, 2, 1, 0, 2, 2, 0, 1, 2, 2, 0, 1, 0, 2, 1, 0, 1, 2, 2, 0, 1, 0, 1, 2, 0, 1, 0, 2, 1, 0, 1, 0, 2, 2, 0, 1, 2, 1, 0, 2, 2, 1, 0, 1, 0, 2, 2, 0, 1, 2, 1, 0, 1, 0, 2, 1, 0, 1, 2, 0, 1, 0, 1, 2, 1
Offset: 1

Views

Author

Jean-Christophe Hervé, Oct 14 2014

Keywords

Comments

Without the zeros, this sequence is equal to the bisection of the Kolakoski sequence A100429 = lengths of runs of 2's in OK sequence.
The Oldenburger-Kolakovski sequence can be obtained back (except the initial 1) by the following substitution rules: insert 1 between two successive nonzero values and 0 -> 11, 1 -> 2, 2 -> 22.

Crossrefs

Showing 1-6 of 6 results.