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-10 of 11 results. Next

A078758 Term in A064389 (variation (4) of Recamán's sequence) where n appears, or 0 if n never appears.

Original entry on oeis.org

1, 4, 2, 35, 33, 3, 5, 16, 14, 12, 10, 8, 6, 188, 58, 186, 184, 23, 25, 7, 9, 11, 13, 15, 17, 182, 48, 46, 50, 1774, 1770, 1772, 1786, 1784, 1766, 40, 1764, 32, 34, 36, 22, 20, 18, 24, 26, 204, 202, 200, 198, 196, 194, 192, 190, 1758, 1762, 1760, 79, 77, 1782, 602
Offset: 1

Views

Author

Reiner Martin, Jan 08 2003

Keywords

Comments

Is it ever 0?
If all a(n)>0, then this is the inverse permutation of A064389. - M. F. Hasler, Nov 03 2014
After 10^12 terms of A064389, the first unknown term of this sequence is 5191516. - Benjamin Chaffin, Oct 09 2016

Crossrefs

Programs

  • PARI
    for(i=1,9e9,for(j=1,#a064389,a064389[j]==i&&print1(j",")+next(2));break) \\ The terms of A064389 must be stored in the vector a064389. - M. F. Hasler, Nov 03 2014

A078759 Height of n-th term in A064389 (variation (4) of Recamán's sequence).

Original entry on oeis.org

1, 2, 3, 2, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 5, 6, 5, 6, 7, 8, 7, 8, 7, 6, 5, 6, 5, 6, 7, 8, 7, 6, 7, 8, 9, 8, 7, 6, 7, 6, 7, 6, 7, 8, 9, 8, 9, 8, 7, 6, 7, 8, 9, 8, 9, 8, 9, 8, 9, 8, 7, 8, 9, 10, 9, 10, 9, 8, 7, 8, 7, 8, 9, 10, 9, 10, 9, 10, 9, 8, 9, 10, 11, 10, 11, 10, 9, 8, 9, 8, 9, 10
Offset: 1

Views

Author

Reiner Martin, Jan 08 2003

Keywords

Crossrefs

Formula

The height of a term in A064389 = number of addition steps - number of subtraction steps to produce it.

A126712 Height of steps in Recamán's sequence A064389.

Original entry on oeis.org

0, 1, 1, 4, 4, 2, 2, 3, 3, 3, 3, 3, 3, 7, 5, 7, 7, 4, 4, 4, 4, 4, 4, 4, 4, 7, 5, 5, 5, 11, 11, 11, 11, 11, 11, 5, 11, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 11, 11, 11, 6, 6, 11, 9, 9, 6, 6, 11, 8, 8, 8, 6, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
Offset: 1

Views

Author

R. J. Mathar, Feb 12 2007

Keywords

Examples

			The heights to reach 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24 in A064389 are b(1,2,3,...) = 0, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 5 etc., as defined by b(n) = b(n-1) + sign(A064389(n) - A064389(n-1)).
Reshuffling sequence b while sorting A064489 into A078758 produces sequence a here, a(n) = b(A078758(n)).
		

Crossrefs

Programs

  • Maple
    A064389 := proc(nmax) local a,n,adiff,newa ; a := [1] ; for n from 2 to nmax do adiff := n ; while true do newa := op(-1,a)-adiff ; if newa >0 and not newa in a then a := [op(a),newa] ; break ; fi ; newa := op(-1,a)+adiff ; if newa >0 and not newa in a then a := [op(a),newa] ; break ; fi ; adiff := adiff+1 ; od ; od ; RETURN(a) ; end: A064389b := proc(a) local n,hei ; hei := [0] ; for n from 2 to nops(a) do hei := [op(hei),op(-1,hei)+sign(op(n,a)-op(n-1,a))] ; od ; RETURN(hei) ; end: inList := proc(list,n) local i ; for i from 1 to nops(list) do if op(i,list) = n then RETURN(i) ; fi ; od ; RETURN(-1) ; end: A078758 := proc(a064389) local a,n,i ; a := [] ; n :=1 ; while true do i := inList(a064389,n) ; if i < 0 then RETURN(a) ; else a := [op(a),i] ; n := n+1 ; fi ; od ; end: nmax := 1800 : a064389 := A064389(nmax) : a078758 := A078758(a064389) : b := A064389b(a064389) : for n from 1 to nops(a078758) do printf("%d, ",op(op(n,a078758),b)) ; od;

A005132 Recamán's sequence (or Recaman's sequence): a(0) = 0; for n > 0, a(n) = a(n-1) - n if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + n.

Original entry on oeis.org

0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 78, 38, 79, 37, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155
Offset: 0

Views

Author

N. J. A. Sloane and Simon Plouffe, May 16 1991

Keywords

Comments

The name "Recamán's sequence" is due to N. J. A. Sloane, not the author!
I conjecture that every number eventually appears - see A057167, A064227, A064228. - N. J. A. Sloane. That was written in 1991. Today I'm not so sure that every number appears. - N. J. A. Sloane, Feb 26 2017
As of Jan 25 2018, the first 13 missing numbers are 852655, 930058, 930557, 964420, 966052, 966727, 969194, 971330, 971626, 971866, 972275, 972827, 976367, ... For further information see the "Status Report" link. - Benjamin Chaffin, Jan 25 2018
From David W. Wilson, Jul 13 2009: (Start)
The sequence satisfies [1] a(n) >= 0, [2] |a(n)-a(n-1)| = n, and tries to avoid repeats by greedy choice of a(n) = a(n-1) -+ n.
This "wants" to be an injection on N = {0, 1, 2, ...}, as it attempts to avoid repeats by choice of a(n) = a(n-1) + n when a(n) = a(n-1) - n is a repeat.
Clearly, there are injections satisfying [1] and [2], e.g., a(n) = n(n+1)/2.
Is there a lexicographically earliest injection satisfying [1] and [2]? (End)
Answer: Yes, of course: The set of injections satisfying [1] and [2] is not empty, so there's a lexicographically least element. More concretely, it starts with the same 23 terms a(0..22) which are known to be minimal, but after a(22) = 41 it has to go on with a(23) = 41 + 23 = 64, since choosing "-" here necessarily yields a non-injective sequence. See A171884. - M. F. Hasler, Apr 01 2019
It appears that a(n) is also the value of "x" and "y" of the endpoint of the L-toothpick structure mentioned in A210606 after n-th stage. - Omar E. Pol, Mar 24 2012
Of course this is not a permutation of the integers: the first repeated term is 42 = a(24) = a(20). - M. F. Hasler, Nov 03 2014. Also 43 = a(18) = a(26). - Jon Perry, Nov 06 2014
Of all the sequences in the OEIS, this one is my favorite to listen to. Click the "listen" button at the top, set the instrument to "103. FX 7 (Echoes)", click "Save", and open the MIDI file with a program like QuickTime Player 7. - N. J. A. Sloane, Aug 08 2017
This sequence cycles clockwise around the OEIS logo. - Ryan Brooks, May 09 2020

Examples

			Consider n=6. We have a(5)=7 and try to subtract 6. The result, 1, is certainly positive, but we cannot use it because 1 is already in the sequence. So we must add 6 instead, getting a(6) = 7 + 6 = 13.
		

References

  • Alex Bellos and Edmund Harriss, Visions of the Universe (2016), Unnumbered pages. Includes Harriss's illustration of the first 65 steps drawn as a spiral.
  • Benjamin Chaffin, N. J. A. Sloane, and Allan Wilks, On sequences of Recaman type, paper in preparation, 2006.
  • Bernardo Recamán Santos, letter to N. J. A. Sloane, Jan 29 1991
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Cf. A057165 (addition steps), A057166 (subtraction steps), A057167 (steps to hit n), A008336, A046901 (simplified version), A064227 (records for reaching n), A064228 (value of n that take a record number of steps to reach), A064284 (no. of times n appears), A064290 (heights of terms), A064291 (record highs), A119632 (condensed version), A063733, A079053, A064288, A064289, A064387, A064388, A064389, A228474 (bidirectional version).
A065056 gives partial sums, A160356 gives first differences.
A row of A066201.
Cf. A171884 (injective variant).
See A324784, A324785, A324786 for the "low points".

Programs

  • Haskell
    import Data.Set (Set, singleton, notMember, insert)
    a005132 n = a005132_list !! n
    a005132_list = 0 : recaman (singleton 0) 1 0 where
       recaman :: Set Integer -> Integer -> Integer -> [Integer]
       recaman s n x = if x > n && (x - n) `notMember` s
                          then (x-n) : recaman (insert (x-n) s) (n+1) (x-n)
                          else (x+n) : recaman (insert (x+n) s) (n+1) (x+n)
    -- Reinhard Zumkeller, Mar 14 2011
    
  • MATLAB
    function a=A005132(m)
    % m=max number of terms in a(n). Offset n:0
    a=zeros(1,m);
    for n=2:m
        B=a(n-1)-(n-1);
        C=0.^( abs(B+1) + (B+1) );
        D=ismember(B,a(1:n-1));
        a(n)=a(n-1)+ (n-1) * (-1)^(C + D -1);
    end
    % Adriano Caroli, Dec 26 2010
    
  • Maple
    h := array(1..100000); maxt := 100000; a := [1]; ad := [1]; su := []; h[1] := 1; for nx from 2 to 500 do t1 := a[nx-1]-nx; if t1>0 and h[t1] <> 1 then su := [op(su), nx]; else t1 := a[nx-1]+nx; ad := [op(ad), nx]; fi; a := [op(a),t1]; if t1 <= maxt then h[t1] := 1; fi; od: # a is A005132, ad is A057165, su is A057166
    A005132 := proc(n)
        option remember; local a, found, j;
        if n = 0 then return 0 fi;
        a := procname(n-1) - n ;
        if a <= 0 then return a+2*n fi;
        found := false;
        for j from 0 to n-1 while not found do
            found := procname(j) = a;
        od;
        if found then a+2*n else a fi;
    end:
    seq(A005132(n), n=0..70); # R. J. Mathar, Apr 01 2012 (reformatted by Peter Luschny, Jan 06 2019)
  • Mathematica
    a = {1}; Do[ If[ a[ [ -1 ] ] - n > 0 && Position[ a, a[ [ -1 ] ] - n ] == {}, a = Append[ a, a[ [ -1 ] ] - n ], a = Append[ a, a[ [ -1 ] ] + n ] ], {n, 2, 70} ]; a
    (* Second program: *)
    f[s_List] := Block[{a = s[[ -1]], len = Length@s}, Append[s, If[a > len && !MemberQ[s, a - len], a - len, a + len]]]; Nest[f, {0}, 70] (* Robert G. Wilson v, May 01 2009 *)
    RecamanSeq[i_Integer] := Fold[With[{lst=Last@#, len=Length@#}, Append[#, If[lst > len && !MemberQ[#, lst - len], lst - len, lst + len]]] &, {0}, Range@i]; RecamanSeq[10^5] (* Mikk Heidemaa, Nov 02 2024 *)
  • PARI
    a(n)=if(n<2,1,if(abs(sign(a(n-1)-n)-1)+setsearch(Set(vector(n-1,i,a(i))),a(n-1)-n),a(n-1)+n,a(n-1)-n))  \\ Benoit Cloitre
    
  • PARI
    A005132(N=1000,show=0)={ my(s,t); for(n=1,N, s=bitor(s,1<M. F. Hasler, May 11 2008, updated M. F. Hasler, Nov 03 2014
    
  • Python
    l=[0]
    for n in range(1, 101):
        x=l[n - 1] - n
        if x>0 and not x in l: l+=[x, ]
        else: l+=[l[n - 1] + n]
    print(l) # Indranil Ghosh, Jun 01 2017
    
  • Python
    def recaman(n):
      seq = []
      for i in range(n):
        if(i == 0): x = 0
        else: x = seq[i-1]-i
        if(x>=0 and x not in seq): seq+=[x]
        else: seq+=[seq[i-1]+i]
      return seq
    print(recaman(1000)) # Ely Golden, Jun 14 2018
    
  • Python
    from itertools import count, islice
    def A005132_gen(): # generator of terms
        a, aset = 0, set()
        for n in count(1):
            yield a
            aset.add(a)
            a = b if (b:=a-n)>=0 and b not in aset else a+n
    A005132_list = list(islice(A005132_gen(),30)) # Chai Wah Wu, Sep 15 2022

Formula

a(k) = A000217(k) - 2*Sum_{i=1..n} A057166(i), for A057166(n) <= k < A057166(n+1). - Christopher Hohl, Jan 27 2019

Extensions

Allan Wilks, Nov 06 2001, computed 10^15 terms of this sequence. At this point all the numbers below 852655 had appeared, but 852655 = 5*31*5501 was missing.
After 10^25 terms of A005132 the smallest missing number is still 852655. - Benjamin Chaffin, Jun 13 2006
Even after 7.78*10^37 terms, the smallest missing number is still 852655. - Benjamin Chaffin, Mar 28 2008
Even after 4.28*10^73 terms, the smallest missing number is still 852655. - Benjamin Chaffin, Mar 22 2010
Even after 10^230 terms, the smallest missing number is still 852655. - Benjamin Chaffin, 2018
Changed "positive" in definition to "nonnegative". - N. J. A. Sloane, May 04 2020

A064387 Variation (2) on Recamán's sequence (A005132): to get a(n), we first try to subtract n from a(n-1): a(n) = a(n-1)-n if positive and not already in the sequence; if not then a(n) = a(n-1)+n+i, where i >= 0 is the smallest number such that a(n-1)+n+i has not already appeared.

Original entry on oeis.org

1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 44, 19, 45, 72, 100, 71, 101, 70, 38, 5, 39, 4, 40, 77, 115, 76, 36, 78, 120, 163, 119, 74, 28, 75, 27, 79, 29, 80, 132, 185, 131, 186, 130, 73, 15, 81, 141, 202
Offset: 1

Views

Author

N. J. A. Sloane, Sep 28 2001

Keywords

Comments

Variation (4) (A064389) is the nicest of these variations.
I would also like to get the following sequences: number of steps before n appears (or 0 if n never appears), list of numbers that never appear, height of n (cf. A064288, A064289, A064290), etc.

References

  • Suggested by J. C. Lagarias.

Crossrefs

Cf. A005132, A046901, A064388, A064389. Agrees with A064389 for first 187 terms, then diverges.

Programs

  • Maple
    h := array(1..100000); maxt := 100000; a := array(1..1000); a[1] := 1; h[1] := 1; for nx from 2 to 1000 do t1 := a[nx-1]-nx; if t1>0 and h[t1] <> 1 then a[nx] := t1; if t1 < maxt then h[t1] := 1; fi; else for i from 0 to 1000 do t1 := a[nx-1]+nx+i; if h[t1] <> 1 then a[nx] := t1; if t1 < maxt then h[t1] := 1; fi; break; fi; od; fi; od; evalm(a);

A064388 Variation (3) on Recamán's sequence (A005132): set s (the step size) initially equal to 2; to get a(n), we first try to subtract s from a(n-1): a(n) = a(n-1)-s if positive and not already in the sequence, in which case we change s to s+1; if not, a(n) = a(n-1)+s+i, where i >= 0 is the smallest number such that a(n-1)+s+i has not already appeared and now we change s to s+i+1.

Original entry on oeis.org

1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 44, 17, 45, 16, 46, 15, 47, 14, 48, 83, 119, 82, 120, 81, 121, 80, 38, 84, 37, 85, 36, 86, 35, 87, 34, 88, 33, 89, 32, 90, 31, 91, 30, 92, 29, 93, 28, 94, 27, 95, 26, 96, 167, 239, 166, 240
Offset: 1

Views

Author

N. J. A. Sloane, Sep 28 2001

Keywords

Comments

Variation (4) (A064389) is the nicest of these variations.
I would also like to get the following sequences: number of steps before n appears (or 0 if n never appears), list of numbers that never appear, height of n (cf. A064288, A064289, A064290), etc.

Crossrefs

Programs

  • BASIC
    rem Chipmunk BASIC v3.6.4(b8) http://www.nicholson.com/rhn/basic/
    max=1000 : dim a(max)
    s=2 : z=1 : a(z)=1 : print str$(z)+",";
    for n=1 to 200
    x=z-s : if x <= 0 then goto yyy
    if a(x)=0 then a(x)=1 : print str$(x)+","; : s=s+1 : z=x : goto xxx
    yyy: for i=0 to max
    x=z+s+i
    if a(x)=0 then a(x)=1 : print str$(x)+","; : s=s+i+1 : z=x : goto xxx
    next i
    xxx: next n
    print : end
    rem Jeremy Gardiner, Feb 22 2014

Extensions

More terms from David Wasserman, Jul 16 2002

A274647 A variation on Recamán's sequence (A005132): to get a(n), we first try to subtract n from a(n-1): a(n) = a(n-1)-n if positive and not already in the sequence; if not then we try to add n: a(n) = a(n-1)+n if not already in the sequence; if this fails we try to subtract 2n from a(n-1), or to add 2n to a(n-1), or to subtract 3n, or to add 3n, etc., until one of these produces a positive number not already in the sequence.

Original entry on oeis.org

0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 66, 91, 65, 38, 94, 123, 93, 124, 92, 59, 127, 162, 126, 89, 51, 90, 50, 132, 174, 131, 87, 177, 223, 176, 128, 79, 29, 80, 28, 81, 27, 82, 26, 83, 141, 200, 140, 201, 139
Offset: 0

Views

Author

Max Barrentine, Aug 12 2016

Keywords

Comments

Is this a permutation of the natural numbers?
After 5.4*10^11 terms, the smallest number which has not appeared is 212. There are 177 numbers under 10000 which have not appeared. - Benjamin Chaffin, Sep 29 2016

Crossrefs

Left inverse: A276342 (also right inverse, if this sequence is a permutation of nonnegative integers).
Cf. A276438 (gives k that was used when computing a(n), with sign).
Cf. A274648 (another variant).

Programs

  • Mathematica
    f[s_List] := Block[{a = b = 0, k = 1, l = s[[-1]], n = Length@ s}, While[ If[l > k*n && !MemberQ[s, l - k*n], a = l - k*n]; If[ !MemberQ[s, l + k*n], b = l + k*n; Break[]]; a == b == 0, k++]; Append[s, If[a > 0, a, b]]]; Nest[f, {0}, 70]
    (* Robert G. Wilson v, Sep 09 2016 *)
  • Python
    l=[0]
    for n in range(1, 101):
        i=1
        while True:
            a=l[n - 1]
            x=a - i*n
            if x>0 and x not in l:
                l.append(x)
                break
            y=a + i*n
            if y>0 and not y in l:
                l.append(y)
                break
            else : i+=1
    print(l) # Indranil Ghosh, Jun 03 2017

Formula

A276342(a(n)) = n for all n.

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

Original entry on oeis.org

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, 68, 93, 66, 38, 67, 37, 5, 36, 69, 35, 70, 34, 71, 33, 72, 32, 73, 31, 74, 30, 75, 29, 76, 28, 77, 27, 78, 26, 79, 133, 188, 132, 189, 131, 190, 130, 191, 129, 192, 128, 193, 127, 60, 134
Offset: 0

Views

Author

Keywords

Comments

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.
The first 14 terms appear in the original OEIS logo. - Philippe Deléham, Mar 01 2013
This is very similar to A064389, and arguably just as nice. - Franklin T. Adams-Watters, Nov 11 2015

Crossrefs

Cf. A118202 (inverse), A005132, A064389.

Programs

  • Maple
    N:= 1000: # get all terms up to the first member > N
    a[0]:= 0:
    davail:= [$1..N]:
    B:= Vector(2*N):
    for n from 1 do
      found:= false;
      for i from 1 to nops(davail) do
        d:= davail[i];
        an:= a[n-1]-d;
        if an > 0 and B[an] = 0 then
          a[n]:= an; found:= true; break
        fi;
        ap:= a[n-1]+d;
        if B[ap] = 0 then
          a[n]:= ap; found:= true; break
        fi
      od:
      if (not found) or (a[n] > N) then break fi;
      davail:= subsop(i=NULL,davail);
      B[a[n]]:= 1;
    od:
    seq(a[i],i=0..n);  # Robert Israel, Nov 17 2015
  • Mathematica
    M = 1000; (* get all terms up to the first member > M *)
    a[0] = 0;
    davail = Range[M];
    B = Array[0&, 2M];
    For[n = 1, True, n++,
    found = False;
    For[i = 1, i <= Length[davail], i++,
    d = davail[[i]];
    an = a[n-1] - d;
    If[an > 0 && B[[an]] == 0,
    a[n] = an; found = True; Break[]
    ];
    ap = a[n-1] + d;
    If[B[[ap]] == 0,
    a[n] = ap; found = True; Break[]
    ]
    ];
    If [Not @ found || (a[n] > M), Break[]];
    davail = ReplacePart[davail, i -> Nothing];
    B[[a[n]]] = 1;
    ];
    Table[a[i], {i, 0, n}] (* Jean-François Alcover, Oct 24 2016, translated from Robert Israel's Maple code *)

Formula

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.

A350578 a(0) = 0; for n > 0, if a(n-1) - n >= 0 and a(n-1) - n has appeared the same or fewer times than a(n-1) + n, then a(n) = a(n-1) - n. Otherwise a(n) = a(n-1) + n.

Original entry on oeis.org

0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 0, 40, 81, 123, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155, 226, 154, 227
Offset: 0

Views

Author

Scott R. Shannon, Jan 07 2022

Keywords

Comments

This sequence is similar to the Recamán sequence A005132 except that here the number chosen to step to, if a(n-1) - n is >= 0, is determined by which of the two possible numbers, a(n-1) - n or a(n-1) + n, has appeared the fewest times. If the number of times these numbers have appeared is the same then a(n) = a(n-1) - n. If a(n-1) - n is less than zero then a(n) = a(n-1) + n.
The first term to differ from A005132 is a(39) = 0. See the examples below. In the first 10^8 terms the largest value is a(99928118) = 842174195, while the smallest number not to have appeared is 366. It is likely all numbers eventually appear although this is unknown.
See the companion sequence A350579 for the first number to appear n times.

Examples

			a(3) = 6 as a(2) = 3 giving the two possible numbers for the next step as 0 or 6. But 0 has already appeared once while 6 has not yet appeared, so 6 is chosen.
a(39) = 0 as a(38) = 39 giving the two possible numbers for the next step as 0 or 78. Both 0 and 78 have already appeared once thus the smaller is chosen. This is the first term to differ from A005132.
a(447) = 934 as a(446) = 487 giving the two possible numbers for the next step as 40 or 934. 40 has already appeared twice while 934 has appeared once, so the later is chosen. This is the first time both possible numbers have already appeared and the larger is chosen.
a(2462) = 551 as a(2461) = 3013 giving the two possible numbers for the next step as 551 or 5475. 551 has already appeared once while 5475 has appeared twice, so the former is chosen. This is the first time both possible numbers have already appeared and the smaller is chosen.
		

Crossrefs

Programs

  • Mathematica
    a[0]=0;a[n_]:=a[n]=If[a[n-1]-n>=0&&Count[Array[a,n-1,0],a[n-1]-n]<=Count[Array[a,n-1,0],a[n-1]+n],a[n-1]-n,a[n-1]+n];Array[a,74,0] (* Giorgos Kalogeropoulos, Jan 07 2022 *)
  • Python
    from itertools import count, islice
    from collections import Counter
    def A350578_gen(): # generator of terms
        yield 0
        b, bcounter = 0, Counter({0})
        for n in count(1):
            b += -n if b-n >= 0 and bcounter[b-n] <= bcounter[b+n] else n
            bcounter[b] += 1
            yield b
    A350578_list = list(islice(A350578_gen(),30)) # Chai Wah Wu, Jan 08 2022

A350579 The first number in A350578 to appear n times.

Original entry on oeis.org

0, 42, 153, 504, 921, 921, 17729, 17729, 17729, 17729, 60610, 60610, 109617, 109617, 109617, 109617, 109617, 109617, 109599, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 658778, 2184074, 2184074, 2184074
Offset: 1

Views

Author

Scott R. Shannon, Jan 07 2022

Keywords

Comments

See A350578 for further details.

Examples

			a(1) = 0 as A350578(0) = 0, thus 0 is the first number to appear one time.
a(2) = 42 as A350578(20) = A350578(24) = 42, thus 42 is the first number to appear two times. This is also true for A005132.
a(3) = 153 as A350578(74) = A350578(78) = A350578(114) = 153, thus 153 is the first number to appear three times.
		

Crossrefs

Programs

  • Mathematica
    a[0]=0;a[n_]:=a[n]=If[a[n-1]-n>=0&&Count[Array[a,n-1,0],a[n-1]-n]<=Count[Array[a,n-1,0],a[n-1]+n],a[n-1]-n,a[n-1]+n];
    Table[k=0;While[Max[Last/@(c=Tally@Array[a,++k,0])]!=i];a[k-1],{i,6}] (* Giorgos Kalogeropoulos, Jan 07 2022 *)
  • Python
    from itertools import count
    from collections import Counter
    def A350579(n):
        b, bcounter = 0, Counter({0})
        for m in count(1):
            if bcounter[b] == n: return b
            b += -m if b-m >= 0 and bcounter[b-m] <= bcounter[b+m] else m
            bcounter[b] += 1 # Chai Wah Wu, Jan 08 2022
Showing 1-10 of 11 results. Next