OFFSET
0,2
LINKS
MATHEMATICA
r[0] = 0; r[n_] := r[n] = If[(d = r[n - 1] - n) >= 0 && FreeQ[Array[r, n, 0], d], d, r[n - 1] + n]; a[n_] := r[2*n] + r[2*n + 1]; Array[a, 100, 0] (* Amiram Eldar, Sep 02 2022 *)
PROG
(PARI) recaman(N)={ my(s, t, v=vector(N)); for(n=1, N, s=bitor(s, 1<<t += if( t<=n || bittest(s, t-n), n, -n)); v[n]=t); concat(0, v); } \\ adapted from A005132
lista(nn) = my(v=recaman(2*nn+2)); vector(nn, k, v[2*k] + v[2*k-1]); \\ Michel Marcus, Sep 02 2022
(Python)
from itertools import count, islice
def A356839_gen(): # generator of terms
b, aset = 0, set()
for n in count(1):
aset.add(b)
a, b = b, c if (c:=b-n)>=0 and c not in aset else b+n
if n&1:
yield a+b
CROSSREFS
KEYWORD
nonn
AUTHOR
Paul Curtz, Aug 31 2022
STATUS
approved