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

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

A081145 a(1)=1; thereafter, a(n) is the least positive integer which has not already occurred and is such that |a(n)-a(n-1)| is different from any |a(k)-a(k-1)| which has already occurred.

Original entry on oeis.org

1, 2, 4, 7, 3, 8, 14, 5, 12, 20, 6, 16, 27, 9, 21, 34, 10, 25, 41, 11, 28, 47, 13, 33, 54, 15, 37, 60, 17, 42, 68, 18, 45, 73, 19, 48, 79, 22, 55, 23, 58, 94, 24, 61, 99, 26, 66, 107, 29, 71, 115, 30, 75, 121, 31, 78, 126, 32, 81, 132, 35, 87, 140, 36, 91, 147, 38, 96, 155, 39
Offset: 1

Views

Author

Don Reble, Mar 08 2003

Keywords

Comments

The sequence is a permutation of the positive integers. The inverse is A081146.
Similar to A100707, except that when we subtract we use the largest possible k.
The 1977 paper of Slater and Velez proves that this sequence is a permutation of positive integers and conjectures that its absolute difference sequence (see A308007) is also a permutation. If we call this the "Slater-Velez permutation of the first kind", then they also constructed another permutation (the 2nd kind), for which they are able to prove that both the sequence (A129198) and its absolute difference (A129199) are true permutations. - Ferenc Adorjan, Apr 03 2007
The points appear to lie on three straight lines of slopes roughly 0.56, 1.40, 2.24 (click "graph", or see the Wilks link). I checked this for the first 10^6 terms using Allan Wilks's C program. See A308009-A308015 for further information about the three lines. - N. J. A. Sloane, May 14 2019

Examples

			a(4)=7 because the previous term is 4 and the differences |3-4|, |5-4| and |6-4| have already occurred.
After 7 we get 3 as the difference 4 has not occurred earlier. 5 follows 14 as the difference 9 has not occurred earlier.
		

Crossrefs

The sequence of differences is A099004 (see also A308007).
Similar to Murthy's sequence A093903, Cald's sequence (A006509) and Recamán's sequence A005132. See also A100707 (another version).
A308021 is an offspring of this sequence. - N. J. A. Sloane, May 13 2019
See A308009-A308015 for the lines that the points lie on.
A308172 gives smallest missing numbers.

Programs

  • Haskell
    import Data.List (delete)
    a081145 n = a081145_list !! (n-1)
    a081145_list = 1 : f 1 [2..] [] where
       f x vs ws = g vs where
         g (y:ys) = if z `elem` ws then g ys else y : f y (delete y vs) (z:ws)
                    where z = abs (x - y)
    -- Reinhard Zumkeller, Jul 02 2015
  • Mathematica
    f[s_] := Block[{d = Abs[Rest@s - Most@s], k = 1}, While[ MemberQ[d, Abs[k - Last@s]] || MemberQ[s, k], k++ ]; Append[s, k]]; NestList[s, {1}, 70] (* Robert G. Wilson v, Jun 09 2006 *)
    f[s_] := Block[{k = 1, d = Abs[Most@s - Rest@s], l = Last@s}, While[MemberQ[s, k] || MemberQ[d, Abs[l - k]], k++ ]; Append[s, k]]; Nest[f, {1}, 70] (* Robert G. Wilson v, Jun 13 2006 *)
  • PARI
    {SV_p1(n)=local(x,v=6,d=2,j,k); /* Slater-Velez permutation - the first kind (by F. Adorjan)*/ x=vector(n);x[1]=1;x[2]=2; for(i=3,n,j=3;k=1;while(k,if(k=bittest(v,j)||bittest(d,abs(j-x[i-1])),j++,v+=2^j;d+=2^abs(j-x[i-1]);x[i]=j))); return(x)} \\ Ferenc Adorjan, Apr 03 2007
    
  • Python
    A081145_list, l, s, b1, b2 = [1,2], 2, 3, set(), set([1])
    for n in range(3, 10**2):
        i = s
        while True:
            m = abs(i-l)
            if not (i in b1 or m in b2):
                A081145_list.append(i)
                b1.add(i)
                b2.add(m)
                l = i
                while s in b1:
                    b1.remove(s)
                    s += 1
                break
            i += 1 # Chai Wah Wu, Dec 15 2014
    

A066201 Array read by antidiagonals upwards: for n-th row (n>=0), T(n,0) = 1; for k > 0, T(n,k) = T(n,k-1)-(n+k-1) if this is positive and has not already appeared in this row, otherwise T(n,k) = T(n,k-1)+(n+k-1).

Original entry on oeis.org

1, 1, 1, 1, 2, 2, 1, 3, 4, 4, 1, 4, 6, 7, 7, 1, 5, 8, 2, 3, 3, 1, 6, 10, 3, 7, 8, 8, 1, 7, 12, 4, 9, 13, 14, 14, 1, 8, 14, 5, 11, 2, 20, 21, 21, 1, 9, 16, 6, 13, 3, 10, 12, 13, 13, 1, 10, 18, 7, 15, 4, 12, 19, 21, 22, 22, 1, 11, 20, 8, 17, 5, 14, 2, 29, 11, 12, 12
Offset: 0

Views

Author

N. J. A. Sloane, Dec 16 2001

Keywords

Examples

			Array begins
   1, 1,  2, 4,  7,  3,  8, 14, 21, 13, ...
   1, 2,  4, 7,  3,  8, 14, 21, 13, 22, ...
   1, 3,  6, 2,  7, 13, 20, 12, 21, 11, ...
   1, 4,  8, 3,  9,  2, 10, 19, 29, 18, ...
   1, 5, 10, 4, 11,  3, 12,  2, 13, 25, ...
   1, 6, 12, 5, 13,  4, 14,  3, 15,  2, ...
   1, 7, 14, 6, 15,  5, 16,  4, 17,  3, ...
   1, 8, 16, 7, 17,  6, 18,  5, 19,  4, ...
		

Crossrefs

Programs

  • Mathematica
    T[, 0] = 1; T[n, k_] := T[n, k] = If[t = T[n, k-1] - (n+k-1); t > 0 && FreeQ[Table[T[n, j], {j, 0, k-1}], t], t, T[n, k-1] + (n+k-1)]; Table[ T[n-k, k], {n, 0, 12}, {k, 0, n}] // Flatten (* Jean-François Alcover, Feb 18 2018 *)

Extensions

More terms from Antonio G. Astudillo (afg_astudillo(AT)lycos.com), Apr 05 2003

A078943 a(1)=1; a(n+1) is either a(n)-n or a(n)+n, where we choose the smallest positive integer that's not among the values a(1), ..., a(n).

Original entry on oeis.org

1, 2, 4, 7, 3, 8, 14, 21, 13, 22, 12, 23, 11, 24, 10, 25, 9, 26, 44, 63, 43, 64, 42, 19
Offset: 1

Views

Author

Leroy Quet, Dec 15 2002

Keywords

Comments

After a(24)=19, there are no more terms because a(24)-24 = -5 is not positive and a(24)+24 = 43 is equal to a(21).
If we only require that a(n+1) be either a(n)-n or a(n)+n, is there a sequence that contains every positive integer exactly once? I.e., can we take a walk on the positive integers starting at 1 and always moving (either left or right) a distance n on the n-th step so that we hit every positive integer exactly once?
A356080 is targeted to be such a sequence, but starting from 0. Its definition incorporates a limited look-ahead condition that is clearly a necessary condition for the sequence not to encounter a dead end (i.e., be finite) and is conjectured to be a sufficient condition. - Peter Munn, Feb 09 2023

Examples

			a(9)=13, so a(10) is either 13-9=4 or 13+9=22. But 4 is not available since it equals a(3), so a(10)=22.
		

Crossrefs

Consists of terms 1 through 25 of A063733.
Cf. A356080.

Extensions

Edited by Dean Hickerson, Dec 18 2002

A174162 a(1) = 2. Let k >= 1 be the minimal integer such that 2*k*a(n-1) + 1 has at least one prime divisor which is not already in the sequence. Then a(n) is the smallest such divisor.

Original entry on oeis.org

2, 5, 11, 23, 47, 19, 3, 7, 29, 59, 17, 103, 619, 2477, 991, 661, 3967, 2267, 907, 191, 383, 13, 53, 107, 43, 173, 347, 139, 31, 83, 167, 67, 269, 359, 719, 1439, 2879, 443, 887, 71, 61, 41, 137, 823, 37, 149, 199, 797, 1063, 709, 2837, 227, 101, 607, 3643, 21859
Offset: 1

Views

Author

Vladimir Shevelev, Mar 10 2010

Keywords

Comments

Conjectures: 1) The sequence is a permutation of prime numbers; 2) k = k(n) runs all positive integers.

Crossrefs

Programs

  • Mathematica
    a = {2}; Do[k = 1; While[(d = Complement[FactorInteger[2 k a[[-1]] + 1][[All, 1]], a]) == {}, k++]; AppendTo[a, Min@d], {n, 50}]; a (* Jinyuan Wang, Feb 26 2020 *)

Extensions

More terms from Jinyuan Wang, Feb 26 2020

A066202 Array T(n,k) (n>=1, k>=1) read by antidiagonals: T(n,n) = 1 for all n; fill in array above diagonal by symmetry; for row n, starting at diagonal T(n,n)=1, for k > n, T(n,k) = T(n,k-1)-(k-1) if this is positive and has not already appeared in this row, otherwise T(n,k) = T(n,k-1)+(k-1).

Original entry on oeis.org

1, 2, 2, 4, 1, 4, 7, 3, 3, 7, 3, 6, 1, 6, 3, 8, 10, 4, 4, 10, 8, 14, 5, 8, 1, 8, 5, 14, 21, 11, 13, 5, 5, 13, 11, 21, 13, 4, 7, 10, 1, 10, 7, 4, 13, 22, 12, 14, 16, 6, 6, 16, 14, 12, 22, 12, 21, 6, 9, 12, 1, 12, 9, 6, 21, 12, 23, 31, 15, 17, 19, 7, 7, 19, 17, 15, 31, 23, 11, 20, 5, 8, 11, 14, 1
Offset: 1

Views

Author

N. J. A. Sloane, Dec 16 2001

Keywords

Examples

			Array begins
1 2 4 7 3 8 ...
2 1 3 6 10 5 ...
4 3 1 4 8 13 ...
7 6 4 1 5 10 ...
		

Crossrefs

Rows give A063733, A066203, A066204. Cf. A066201 for another version.

Programs

  • Mathematica
    T[n_, n_] = 1; T[n_, k_] /; k < n := T[n, k] = T[k, n]; T[n_, k_] := T[n, k] = If[t = T[n, k - 1] - (k - 1); t > 0 && FreeQ[Table[T[n, j], {j, 1, k - 1}], t], t, T[n, k - 1] + (k - 1)]; Table[T[n - k + 1, k], {n, 1, 13}, {k, 1, n}] // Flatten (* Jean-François Alcover, Feb 18 2018 *)

Extensions

More terms from Antonio G. Astudillo (afg_astudillo(AT)lycos.com), Apr 06 2003

A141126 a(n+1) = a(n)-n^2 if positive and new, else a(n+1) = a(n)+n^2; a(0)=1.

Original entry on oeis.org

1, 1, 2, 6, 15, 31, 56, 20, 69, 5, 86, 186, 65, 209, 40, 236, 11, 267, 556, 232, 593, 193, 634, 150, 679, 103, 728, 52, 781, 1565, 724, 1624, 663, 1687, 598, 1754, 529, 1825, 456, 1900, 379, 1979, 298, 2062, 213, 2149, 124, 2240, 4449, 2145, 4546, 2046, 4647
Offset: 0

Views

Author

Reinhard Zumkeller, Jun 05 2008

Keywords

Crossrefs

Cf. A063733.

Programs

  • Mathematica
    s={1};Do[nx=s[[-1]]-n^2;If[nx>0&&!MemberQ[s,nx],AppendTo[s,nx],AppendTo[s,nx+2n^2]],{n,0,51}];s (* James C. McMahon, Jul 17 2025 *)

A174161 a(1) = 2. Let k >= 1 be the minimal integer such that 2*k*a(n-1) - 1 has at least one prime divisor which is not already in the sequence. Then a(n) is the smallest such divisor.

Original entry on oeis.org

2, 3, 5, 19, 37, 73, 29, 23, 7, 13, 17, 11, 43, 257, 79, 157, 313, 139, 277, 41, 163, 31, 61, 487, 59, 47, 281, 1123, 449, 359, 239, 53, 211, 421, 101, 67, 89, 71, 283, 113, 677, 2707, 5413, 433, 173, 691, 1381, 251, 167, 1669, 5563, 7417, 44501, 431, 1723, 2297
Offset: 1

Views

Author

Vladimir Shevelev, Mar 10 2010

Keywords

Comments

Conjectures: 1) The sequence is a permutation of prime numbers; 2) k = k(n) runs all positive integers.

Crossrefs

Programs

  • Mathematica
    a = {2}; Do[k = 1; While[(d = Complement[FactorInteger[2 k a[[-1]] - 1][[All, 1]], a]) == {}, k++]; AppendTo[a, Min@d], {n, 50}]; a (* Ivan Neretin, Dec 04 2018 *)

Extensions

Terms from a(22) onwards corrected by Ivan Neretin, Dec 04 2018

A383730 a(0) = 0, a(n) = a(n-1) + A002260(n) * (-1)^(n-1) if not already in the sequence, otherwise a(n) = a(n-1) - A002260(n) * (-1)^(n-1).

Original entry on oeis.org

0, 1, 2, 4, 3, 5, 8, 9, 7, 10, 6, 5, 7, 4, 8, 13, 12, 14, 11, 15, 20, 26, 25, 27, 24, 28, 23, 29, 22, 21, 19, 16, 20, 15, 21, 14, 22, 21, 23, 20, 24, 19, 25, 32, 40, 49, 48, 50, 47, 51, 46, 52, 45, 53, 44, 54, 55, 57, 60, 64, 59, 65, 58, 66, 75, 85, 74, 73, 71
Offset: 0

Views

Author

Markel Zubia, May 06 2025

Keywords

Comments

This sequence is a bidirectional form of Recamán's sequence.
Another way to define the sequence: starting at 0, take steps of size 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, ... alternating left and right while avoiding repeated values (negative values are allowed).
The sequence is unbounded either above or below.
Conjecture: the sequence is unbounded both above and below.
Conjecture: each integer appears finitely often.
It exhibits a mix of chaotic and periodic behavior, including long plateaus and sudden large jumps.
Around term 25000, the sequence settles near -3000 in a visually fractal structure. After ~1.85 million terms, it appears to settle again near -500000. Astonishingly, after ~66.7 million steps, it jumps sharply from around -500000 to +4.51 million.

Examples

			a(1) = 0 + 1.
a(2) = 0 + 1 + 1 = 2, since 0 + 1 - 1 = 0 already appears in the sequence, as a(0) = 0.
a(6) = 0 + 1 + 1 + 2 - 1 + 2 + 3 = 8.
		

Crossrefs

Cf. A005132.
Other bidirectional extensions of Recamán's sequence: A063733, A079053, A064288, A064289, A064387, A064388, A064389, A228474.
Cf. A002260.

Programs

  • Python
    def a(n):
        t, k, curr = 1, 1, 0
        seen = set()
        for i in range(n):
            seen.add(curr)
            step = (-1)**i * t
            if curr + step not in seen:
                curr = curr + step
            else:
                curr = curr - step
            t += 1
            if t > k:
                t, k = 1, k + 1
        return curr

A234588 Lexicographically earliest sequence S with property that a(n) is the a(n)-th absolute first difference of S.

Original entry on oeis.org

1, 2, 4, 5, 9, 14, 8, 10, 18, 27, 17, 6, 11, 15, 29, 44, 19, 36, 54, 35, 21, 42, 23, 46, 25, 50, 28, 55, 83, 112, 31, 62, 33, 66, 37, 72, 108, 71, 39, 78, 41, 82, 124, 45, 89, 134, 88, 48, 96, 51, 101, 152, 53, 106, 160, 105, 57, 114, 59, 118, 61, 122, 184, 64
Offset: 1

Views

Author

Eric Angelini, Dec 31 2013

Keywords

Comments

A kind of self-describing sequence.
Recamán's sequence A005132 is also self-describing in this sense, but comes lexicographically after this one (and you have to drop the initial "0").
If we want S to be monotonically increasing, we get A063733.

Examples

			If n = 1 2 3 4 5  6 7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
a(n) = 1 2 4 5 9 14 8 10 18 27 17, 6 11 15 29 44 19 36 54 35 21 42 23 46 25 50 28 55 ...
diff =  1 2 1 4 5  6 2  8  9  10 11 5  4  14 15 25 17 18 19 14 21 19 23 21 25 22
d-rank= 1 2 3 4 5  6 7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
hit:    * *   * *  *    *  *   *  *     *  *  *     *
S is tricky to compute; the rule for a(n+1) is "always use the smallest integer not yet in S and not leading to a contradiction".
'14' is in S and '14' says: "The 14th absolute first difference in S equals 14" -- which is true.
		

References

  • Eric Angelini, Posting to Sequence Fans Mailing List, Nov 26, 2010

Crossrefs

Extensions

More terms from Jon E. Schoenfield, Jan 11 2014
Showing 1-10 of 11 results. Next