OFFSET
0,2
COMMENTS
Differs from Cald's sequence A006509 for first time at n=116 (or 117, depending on offset).
LINKS
FORMULA
a(n) = A064365(n) + 1. - Thomas Ordowski, Dec 05 2016
MAPLE
M1:=500000; a:=array(0..M1); have:=array(1..M1); a[0]:=1; for n from 1 to M1 do have[n]:=0; od: have[1]:=1;
M2:=2000; nmax:=M2;
for n from 1 to M2 do p:=ithprime(n); i:=a[n-1]-p; j:=a[n-1]+p;
if i >= 1 and have[i]=0 then a[n]:=i; have[i]:=1;
elif j <= M1 then a[n]:=j; have[j]:=1;
else nmax:=n-1; break; fi; od: [seq(a[n], n=0..M2)];
MATHEMATICA
a = {1}; Do[If[And[#1 > 0, ! MemberQ[a, #1]], AppendTo[a, #1], AppendTo[a, #2]] & @@ {#1 - #2, #1 + #2} & @@ {a[[n - 1]], Prime[n - 1]}, {n, 2, 62}]; a (* Michael De Vlieger, Dec 05 2016 *)
PROG
(Haskell)
import Data.Set (singleton, notMember, insert)
a117128 n = a117128_list !! n
a117128_list = 1 : f 1 a000040_list (singleton 1) where
f x (p:ps) s | x' > 0 && x' `notMember` s = x' : f x' ps (insert x' s)
| otherwise = xp : f xp ps (insert xp s)
where x' = x - p; xp = x + p
-- Reinhard Zumkeller, Apr 26 2012
(Python)
from sympy import primerange, prime
def aupton(terms):
alst = [1]
for n, pn in enumerate(primerange(1, prime(terms)+1), start=1):
x = alst[-1] - pn
alst += [x if x > 0 and x not in alst else alst[-1] + pn]
return alst
print(aupton(61)) # Michael S. Branicky, May 30 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Apr 20 2006
STATUS
approved