OFFSET
1,2
LINKS
Michel Marcus, Table of n, a(n) for n = 1..10000
MATHEMATICA
r[-1] = 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 - 1] + r[2*n])/4; Array[a, 100] (* 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); v; } \\ adapted from A005132
lista(nn) = my(v=recaman(2*nn+2)); vector(nn, k, v[2*k-1] + v[2*k])/4; \\ Michel Marcus, Sep 13 2022
(Python)
from itertools import count, islice
def A356870_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 not n&1:
yield a+b>>2
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Paul Curtz, Sep 02 2022
EXTENSIONS
New name, data and offset from Michel Marcus, Sep 13 2022
STATUS
approved