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-4 of 4 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

A181391 Van Eck's sequence: For n >= 1, if there exists an m < n such that a(m) = a(n), take the largest such m and set a(n+1) = n-m; otherwise a(n+1) = 0. Start with a(1)=0.

Original entry on oeis.org

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, 2, 9, 0, 4, 9, 3, 6, 14, 0, 6, 3, 5, 15, 0, 5, 3, 5, 2, 17, 0, 6, 11, 0, 3, 8, 0, 3, 3, 1, 42, 0, 5, 15, 20, 0, 4, 32, 0, 3, 11, 18, 0, 4, 7, 0, 3, 7, 3, 2, 31, 0, 6, 31, 3, 6, 3, 2, 8, 33, 0, 9, 56, 0, 3, 8, 7, 19, 0, 5, 37, 0, 3, 8, 8, 1
Offset: 1

Views

Author

Jan Ritsema van Eck, Oct 17 2010, Oct 19 2010

Keywords

Comments

The name "Van Eck's sequence" is due to N. J. A. Sloane, not the author!
Note that it is obvious from the definition that a(n) < n for all n. - N. J. A. Sloane, Jun 20 2019. Even stronger, a(n)+a(n+1) < n for all n, since the a(n+1) implies that a(n-a(n+1)) = a(n). - Jan Ritsema van Eck, Jun 30 2019
Starting with a number different from 0, for instance with 1, gives a different but similar sequence. See A171911-A171918 for examples.
Examination of the first 10^6 terms suggests that lim sup a(n)/n = 1. Cf. A171866/A171867. - David Applegate and N. J. A. Sloane, Oct 18 2010
From Jan Ritsema van Eck, Oct 25 2010: (Start)
Theorem: There are infinitely many zeros.
Proof: Suppose not. Then from a certain point on, no new terms appear, so the sequence is bounded and nonzero. Let M be the maximal term. Any block of length M determines the rest of the sequence.
But there are only M^M different blocks of length M containing the numbers 1 through M.
So a block must repeat, and so the sequence eventually becomes periodic. The periodic part does not contain any zeros.
Suppose the period has length p, and starts at term r, with a(r)=x, ..., a(r+p-1)=z, a(r+p)=x, ... There is another z after q <= p steps, which is immediately followed by q.
But this q implies that a(r-1)=z. Therefore the periodic part really began at step r-1.
Repeating this shows that the periodic part starts at a(1). But a(1)=0, and the periodic part cannot contain a 0. Contradiction. (End)
An alternative wording of the definition: For n>=1, if there exists an m < n such that a(m) = a(n), take the largest such m, otherwise take m = n; set a(n+1) = n-m. Start with a(1)=0. - Arie Bos, Dec 10 2010
Conjectures: (i) lim sup a(n)/n = 1; (ii) gaps between 0's are about log_10 n; (iii) every number eventually appears. - N. J. A. Sloane, in lecture "The OEIS: The Major Problems", Conference for 50th Anniversary of the OEIS, Rutgers University, Oct 10 2014. (Added Jun 16 2019.)
Conjecture: every pair of nonnegative integers (x,y) other than (1,1) and (x,x+1) for x>0 appear as consecutive entries (that is, a(i) = x, a(i+1) = y, for some i). - László Kozma, Aug 09 2016. Correction from Tomas Rokicki, Jun 19 2019: The pair (x,x+1) only occurs at (0,1), as it would imply distinct values x positions previously.
As mentioned in an earlier comment, for any k >= 0 there is a "van Eck" sequence E(k) starting with k and extended using the same rule (cf. A171911-A171918). The initial E(k)(1) = k is followed by at least k initial terms from this sequence A181391 = E(0): E(k)(n+1) = E(0)(n) for all n <= k and beyond, as long as E(0)(n) != k. - M. F. Hasler, Jun 11 2019
Comment from Jordan Linus, circa Jun 16 2019, from an online comment added to the Haran-Sloane video: (Start)
Theorem: limsup a(n)/sqrt(n) >= 1.
Proof: Whenever a(n)=0, either there have been sqrt(n) zeros in the sequence, thus sqrt(n) new distinct numbers (and at least one bigger than sqrt(n)), or there have been fewer than sqrt(n) zeros in the sequence, and thus there is a gap of at least sqrt(n) between two zeros (and the term after the second zero is at least sqrt(n)). So either way there is a term >= sqrt(n). (End)
The long-term behavior of the sequence E(k) appears to be the same for all k, although the individual numbers differ. Empirically modeled up to 2^25 terms of E(k) for k between 0 and 9. - Po-chia Chen, Jun 18 2019
After searching the first 318 billion entries, the smallest number not appearing is 645315850; the smallest pair not of the form (1,1), (0,a), or (x,x+1) not appearing is (268,5). - Tomas Rokicki, Jun 19 2019
Theorem: i-a(i) is unique for all i, a(i)>0. Put differently: i-a(i)<>j-a(j) for all i,j, a(i)>0 and j>i. Proof: if a(i-1)=a(j-1)=x, a(j) can be at most j-i because there is by definition not another x between a(j-1) and a(j-a(j)-1). If a(i-1)<>a(j-1), it follows that a(i-a(i)-1)<>a(j-a(j)-1). Either way i-a(i)<>j-a(j). A special case of this is that pairs (x,x+1) cannot occur for x>0 (as remarked above); similarly, triples (x,y,x+2) cannot occur and so on. Also, since a(i-a(i+1))=a(i) by definition, i-a(i+1)-a(i) is unique for all i, a(i+1) and a(i)>0. A simple example is that triples (x,y,x+1) cannot occur for y>0. Many other "impossible patterns" can be derived. - Jan Ritsema van Eck, Jul 22 2019
After 10^12 terms, the smallest number not appearing is 1732029957; the smallest pair not of the form (1,1), (0,a), or (x,x+1) not appearing is (528,5); there have been 90689534032 zeros. - Benjamin Chaffin, Sep 11 2019
Similar to E(k) above, the sequence E(k,l,...,m) could be defined as the sequence starting with k,l,...,m and continuing using Van Eck's rule. For example, E(1,1) is 1,1,1,... and has period 1. The smallest possible period greater than 1 is 42, attained by E(37, 42, 7, 42, 2, 5, 22, 42, 4, 11, 42, 3, 21, 42, 3, 3, 1, 25, 38, 42, 6, 25, 4, 14, 42, 5, 20, 42, 3, 13, 42, 3, 3, 1, 17, 36, 42, 6, 17, 4, 17, 2). More info: https://redd.it/dbdhpj - Michiel De Muynck, Sep 30 2019
If the rule a(n+1)=0 (when a(n) has not been seen before) is replaced by a(n+1)=a(a(n)) and a(0) is set to 0, then the resulting sequence is A025480. - David James Sycamore, Nov 01 2019

Examples

			We start with a(1) = 0. 0 has not appeared before, so the rule says a(2) = 0. Now 0 HAS occurred before, at a(1), which is 1 term before, so a(3) = 1. 1 has not occurred before, so a(4) = 0. 0 appeared most recently at term a(2), which is 2 terms earlier, so a(5) = 2. 2 has not occurred before, so a(6) = 0. And so on.
		

Crossrefs

Cf. A171862, A171863, A171864, A171865, A171866, A171867, A171887, A171888, A171889, A171896, A171897 (numbers in order of appearance), A171898, A171899.
Cf. also A171911-A171918 (starting with other numbers than 0), A171951-A171956, A171957, A171958, A175041, A175100, A268755, A274425, A309363 (using 2 instead of 0 to mark a new value).
A276457 and A337980 are of the same type.
Cf. A025480.

Programs

  • Haskell
    import Data.List (findIndex, unfoldr)
    import Data.Maybe (fromMaybe)
    a181391 n = a181391_list !! (n-1)
    a181391_list = 0 : (unfoldr g [0]) where
       g xs = Just (m, m : xs) where
            m = 1 + fromMaybe (-1) (findIndex (== head xs) $ tail xs)
    -- Reinhard Zumkeller, Oct 31 2011
    
  • J
    NB. see www.Jsoftware.com
    (,  # <:@- }:  i: {:)^:({.`}.) 100 0 NB. Arie Bos, Dec 10 2010
    
  • Julia
    function A181391(len)
        L = [0, 0]
        for n in 2:len
            k = findlast(m -> L[n] == L[m], 1:n-1)
            push!(L, k == nothing ? 0 : n - k)
        end
    L end
    println(A181391(96)) # Peter Luschny, May 19 2019
    
  • Maple
    M:=10000;
    a:=Array(1..M);
    last:=Array(0..M,-1);
    a[1]:=0;
    a[2]:=0;
    last[0]:=2;
    nxt:=1;
    for n from 3 to M do
    hist:=last[nxt];
    a[n]:=nxt;
    last[nxt]:=n;
    nxt:=0;
    if hist>0 then nxt:=n-hist; fi;
    od:
    [seq(a[n],n=1..M)];
    # N. J. A. Sloane, Oct 18 2010
  • Mathematica
    m = 100; ClearAll[a, last]; a[] = 0; last[] = -1; last[0] = 2; nxt = 1; Do[ hist = last[nxt]; a[n] = nxt; last[nxt] = n; nxt = 0; If[ hist > 0 , nxt = n - hist], {n, 3, m}]; Table[a[n], {n, 1, m}] (* Jean-François Alcover, Dec 01 2011, after Maple program by N. J. A. Sloane *)
    A181391L = Nest[# /. {{Longest[p___], a_, q___, a_} :> {p, a, q, a, Length[{a, q}]}, {a___} :> {a, 0}} &, {}, #] &; A181391L[97] (* JungHwan Min, Jan 14 2017 *)
  • PARI
    A181391_vec(N,a=0,i=Map())={vector(N,n,a=if(n>1,iferr(n-mapget(i,a),E,0)+mapput(i,a,n)))} \\ M. F. Hasler, Jun 11 2019
    
  • Python
    A181391 = [0,0]
    for n in range(1,10**4):
        for m in range(n-1,-1,-1):
            if A181391[m] == A181391[n]:
                A181391.append(n-m)
                break
        else:
            A181391.append(0) # Chai Wah Wu, Aug 14 2014
    
  • Python
    A181391 = [0]
    last_pos = {}
    for i in range(10**4):
        new_value = i - last_pos.get(A181391[i], i)
        A181391.append(new_value)
        last_pos[A181391[i]] = i
    # Ehsan Kia, Jun 12 2019
    
  • R
    vaneckw <-function(howmany = 100){
    howmany = round(howmany[1])
    ve = c(0,0)
    for (jj in 2:(howmany)) {
    thefind <- which(ve[1:(jj-1)] == ve[jj])
    if (length(thefind)){
    ve <- c(ve,jj-thefind[length(thefind)])
    } else ve <- c(ve,0)
    }
    return(invisible(ve))
    } #Carl Witthoft, Jun 14 2019

A171898 Forward van Eck transform of A181391.

Original entry on oeis.org

1, 2, 6, 2, 2, 5, 1, 6, 42, 5, 2, 4, 5, 9, 14, 3, 9, 3, 15, 2, 4, 6, 17, 3, 6, 32, 56, 5, 3, 131, 5, 11, 5, 3, 20, 6, 2, 8, 15, 31, 170, 3, 31, 18, 3, 3, 33, 5, 1, 11, 46, 56, 4, 37, 152, 307, 3, 7, 92, 4, 7, 62, 52, 3, 42, 3, 6, 2, 19, 6, 8, 3, 9, 3, 650, 2, 23, 8, 223, 7, 206, 3, 21, 25, 5, 8
Offset: 1

Views

Author

N. J. A. Sloane, Oct 22 2010

Keywords

Comments

Given a sequence a, the forward van Eck transform b is defined as follows: If a(n) also appears again in a later position, let a(m) be the next occurrence, and set b(n)=m-n; otherwise b(n)=0.
This is a permutation of the positive terms in A181391, where each term m > 0 from that sequence is shifted backwards m+1 positions. - Jan Ritsema van Eck, Aug 16 2019
The backwards van Eck transform searches backwards for a repeated value: if a(n) also has appeared in earlier positions, a(m)=a(n) with mR. J. Mathar, Jun 24 2021

Crossrefs

Cf. A181391 (van Eck's sequence), A171899, A171942.

Programs

  • Maple
    ECKf:=proc(a) local b,i,m,n;
    if whattype(a) <> list then RETURN([]); fi:
    b:=[];
    for n from 1 to nops(a)-1 do
    # does a(n) appear again?
    m:=0;
    for i from n+1 to nops(a) do
    if (a[i]=a[n]) then m:=i-n; break; fi
    od:
    b:=[op(b),m];
    od:
    b:=[op(b),0];
    RETURN(b);
    end:
  • Mathematica
    terms = 100;
    m = 14 terms; (* Increase m until no zero appears in the output *)
    ClearAll[b, last]; b[] = 0; last[] = -1; last[0] = 2; nxt = 1;
    Do[hist = last[nxt]; b[n] = nxt; last[nxt] = n; nxt = 0; If[hist > 0, nxt = n - hist], {n, 3, m}];
    A181391 = Array[b, m];
    ECKf[a_List] := Module[{b = {}, i, m, n}, For[n = 1, n <= Length[a]-1, n++, m = 0; For[i = n+1, i <= Length[a], i++, If[a[[i]] == a[[n]], m = i-n; Break[]]]; b = Append[b, m]]; b = Append[b, 0]; Return[b]];
    ECKf[A181391][[;; terms]] (* Jean-François Alcover, Oct 30 2020, after Maple *)

Formula

From Jan Ritsema van Eck, Aug 16 2019: (Start)
A181391(i+a(i)+1) = a(i) for any i, a(i)>0.
Conversely, a(j-A181391(j)-1) = A181391(j) for any j, A181391(j)>0. (End)

A171934 Backwards van Eck transform of A000010.

Original entry on oeis.org

0, 1, 0, 1, 0, 2, 0, 3, 2, 2, 0, 2, 0, 5, 0, 1, 0, 4, 0, 4, 8, 11, 0, 4, 0, 5, 8, 2, 0, 6, 0, 15, 8, 2, 0, 8, 0, 11, 4, 6, 0, 6, 0, 11, 6, 23, 0, 8, 6, 6, 0, 7, 0, 16, 14, 4, 20, 29, 0, 12, 0, 31, 6, 13, 0, 16, 0, 4, 0, 14, 0, 2, 0, 11, 20, 2, 16, 6, 0, 12, 0, 7, 0, 6, 0, 37, 0, 6, 0, 6, 18, 23, 16, 47
Offset: 1

Views

Author

N. J. A. Sloane, Oct 24 2010

Keywords

Comments

Given a sequence a, the backwards van Eck transform b is defined as follows: If a(n) has already appeared in a, let a(m) be the most recent occurrence, and set b(n)=n-m; otherwise b(n)=0. (Comment from A171899).

Crossrefs

Programs

  • Mathematica
    Block[{a = Array[EulerPhi, 94], b = {}, m}, Do[If[! IntegerQ[m[#]], Set[m[#], i]; AppendTo[b, 0], AppendTo[b, i - m[#]]; Set[m[#], i]] &@ a[[i]], {i, Length[a]}]; b] (* Michael De Vlieger, Apr 06 2021 *)
  • PARI
    up_to = 105;
    backVanEck_transform(invec) = { my(om = Map(), outvec = vector(length(invec)), u=1); for(i=1, length(invec), if(mapisdefined(om,invec[i]), my(pp = mapget(om, invec[i])); outvec[i] = i-pp, outvec[i] = 0); mapput(om,invec[i],i)); outvec; };
    v171934 = backVanEck_transform(vector(up_to,n,eulerphi(n)));
    A171934(n) = v171934[n]; \\ Antti Karttunen, Apr 06 2021
Showing 1-4 of 4 results.