|
|
A261573
|
|
A variation of Recamán's sequence A005132: Define a(0) = 0, and for n > 0, a(n) = a(n-1) - (n+2) if positive and not already in the sequence, otherwise a(n) = a(n-1) + (n+2).
|
|
3
|
|
|
0, 3, 7, 2, 8, 1, 9, 18, 28, 17, 5, 18, 4, 19, 35, 52, 34, 15, 35, 14, 36, 13, 37, 12, 38, 11, 39, 10, 40, 71, 103, 70, 104, 69, 33, 70, 32, 71, 31, 72, 30, 73, 29, 74, 120, 167, 119, 168, 118, 67, 119, 66, 120, 65, 121, 64, 6, 65, 125, 186, 124, 61, 125, 60, 126, 59, 127, 58, 128, 57
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,2
|
|
COMMENTS
|
As in Recamán's sequence, terms are repeated, the first being 18 = a(7) = a(11).
More generally, for k >= 0, a_k(0) = 0, and for n > 0, a_k(n) = a_k(n-1) - (n+k) if positive and not already in the sequence, otherwise a_k(n) = a_k(n-1) + (n+k).
For k = 0, this is Recamán's sequence A005132.
|
|
LINKS
|
|
|
MATHEMATICA
|
f[s_List] := Block[{a = s[[-1]], len = Length@ s}, Append[s, If[a > len + 1 && ! MemberQ[s, a - len - 2], a - len - 2, a + len + 2]]]; Nest[f, {0}, 70] (* Robert G. Wilson v, Sep 08 2015 *)
|
|
PROG
|
(Python)
def sequence(n, k):
"""For n > 0 and k >= 0, generates the first n terms of the sequence"""
A, a = {0}, 0
yield a
for n in range(1, n + 1):
a = a - (n + k)
if a > 0 and a not in A:
A.add(a)
yield a
else:
a = a + 2 * (n + k)
A.add(a)
yield a
# List of the first 1000 terms of the sequence with k = 2.
list(sequence(1000, 2))
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|