

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) = nm; otherwise a(n+1) = 0. Start with a(1)=0.


47



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
(list;
graph;
refs;
listen;
history;
text;
internal format)



OFFSET

1,5


COMMENTS

The name "Van Eck's sequence" is due to N. J. A. Sloane, not the author!
Starting with a number different from 0, for instance with 1, gives a different but similar sequence. See A171911A171918 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. 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+p1)=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(r1)=z. Therefore the periodic part really began at step r1.
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 definition of the sequence: 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) = nm. Start with a(1)=0.  Arie Bos, Dec 10 2010
Conjecture: every pair of nonnegative integers (x,y) other than (1,1) appear as consecutive entries (a(i) = x, a(i+1) = y, for some i).  László Kozma, Aug 09 2016


LINKS

N. J. A. Sloane, Table of n, a(n) for n = 1..100000
N. J. A. Sloane, Fortran program


EXAMPLE

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.


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:=nhist; 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}] (* JeanFranç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 *)


PROG

(J) # see www.Jsoftware.com
(, # <:@ }: i: {:)^:({.`}.) 100 0 NB. Arie Bos, Dec 10 2010
(Haskell)
import Data.List (findIndex, unfoldr)
import Data.Maybe (fromMaybe)
a181391 n = a181391_list !! (n1)
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
(Python)
A181391 = [0, 0]
for n in range(1, 10**4):
....for m in range(n1, 1, 1):
........if A181391[m] == A181391[n]:
............A181391.append(nm)
............break
....else:
........A181391.append(0)
# Chai Wah Wu, Aug 14 2014


CROSSREFS

Cf. A171862, A171863, A171864, A171865, A171866, A171867, A171887, A171888, A171889, A171898, A171899.
Cf. also A171911A171918, A171951A171956, A171957, A171958, A175041, A175100, A268755, A274425.
A276457 is of the same ilk.
Sequence in context: A112803 A124242 A112274 * A262670 A082054 A044943
Adjacent sequences: A181388 A181389 A181390 * A181392 A181393 A181394


KEYWORD

easy,nonn,nice


AUTHOR

Jan Ritsema van Eck (j.ritsemavaneck(AT)planet.nl), Oct 17 2010, Oct 19 2010


STATUS

approved



