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.

A118201 Smallest difference such that both difference and number do not occur previously.

This page as a plain text file.
%I A118201 #27 Oct 25 2016 02:46:22
%S A118201 0,1,3,6,2,7,13,20,12,21,11,22,10,23,9,24,8,25,43,62,42,63,41,18,44,
%T A118201 68,93,66,38,67,37,5,36,69,35,70,34,71,33,72,32,73,31,74,30,75,29,76,
%U A118201 28,77,27,78,26,79,133,188,132,189,131,190,130,191,129,192,128,193,127,60,134
%N A118201 Smallest difference such that both difference and number do not occur previously.
%C A118201 Similar to Recamán's sequence (A005132), but increases the difference to avoid duplicating values. Conjecture that every nonnegative integer occurs in this sequence. Evaluating through n=20000, the smallest number that has not occurred is 139.
%C A118201 The first 14 terms appear in the original OEIS logo. - _Philippe Deléham_, Mar 01 2013
%C A118201 This is very similar to A064389, and arguably just as nice. - _Franklin T. Adams-Watters_, Nov 11 2015
%H A118201 Alois P. Heinz, <a href="/A118201/b118201.txt">Table of n, a(n) for n = 0..20000</a>
%F A118201 a(n+1) = a(n)-d or a(n)+d, where a(n+1) must be positive and must not have occurred previously in the sequence; choose the smallest positive d such that this is possible where d is not |a(m+1)-a(m)| for any m < n; if both a(n)-d and a(n)+d have not occurred, choose a(n)-d.
%p A118201 N:= 1000: # get all terms up to the first member > N
%p A118201 a[0]:= 0:
%p A118201 davail:= [$1..N]:
%p A118201 B:= Vector(2*N):
%p A118201 for n from 1 do
%p A118201   found:= false;
%p A118201   for i from 1 to nops(davail) do
%p A118201     d:= davail[i];
%p A118201     an:= a[n-1]-d;
%p A118201     if an > 0 and B[an] = 0 then
%p A118201       a[n]:= an; found:= true; break
%p A118201     fi;
%p A118201     ap:= a[n-1]+d;
%p A118201     if B[ap] = 0 then
%p A118201       a[n]:= ap; found:= true; break
%p A118201     fi
%p A118201   od:
%p A118201   if (not found) or (a[n] > N) then break fi;
%p A118201   davail:= subsop(i=NULL,davail);
%p A118201   B[a[n]]:= 1;
%p A118201 od:
%p A118201 seq(a[i],i=0..n);  # _Robert Israel_, Nov 17 2015
%t A118201 M = 1000; (* get all terms up to the first member > M *)
%t A118201 a[0] = 0;
%t A118201 davail = Range[M];
%t A118201 B = Array[0&, 2M];
%t A118201 For[n = 1, True, n++,
%t A118201 found = False;
%t A118201 For[i = 1, i <= Length[davail], i++,
%t A118201 d = davail[[i]];
%t A118201 an = a[n-1] - d;
%t A118201 If[an > 0 && B[[an]] == 0,
%t A118201 a[n] = an; found = True; Break[]
%t A118201 ];
%t A118201 ap = a[n-1] + d;
%t A118201 If[B[[ap]] == 0,
%t A118201 a[n] = ap; found = True; Break[]
%t A118201 ]
%t A118201 ];
%t A118201 If [Not @ found || (a[n] > M), Break[]];
%t A118201 davail = ReplacePart[davail, i -> Nothing];
%t A118201 B[[a[n]]] = 1;
%t A118201 ];
%t A118201 Table[a[i], {i, 0, n}] (* _Jean-François Alcover_, Oct 24 2016, translated from _Robert Israel_'s Maple code *)
%Y A118201 Cf. A118202 (inverse), A005132, A064389.
%K A118201 nonn,look,nice
%O A118201 0,3
%A A118201 _Franklin T. Adams-Watters_, Apr 14 2006