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.

A117128 Recamán transform of primes (another version): a(0)=1; for n>0, a(n) = a(n-1) - prime(n) if that number is positive and not already in the sequence, otherwise a(n) = a(n-1) + prime(n).

This page as a plain text file.
%I A117128 #25 May 31 2021 03:26:55
%S A117128 1,3,6,11,4,15,2,19,38,61,32,63,26,67,24,71,18,77,16,83,12,85,164,81,
%T A117128 170,73,174,277,384,275,162,35,166,29,168,317,468,311,148,315,142,321,
%U A117128 140,331,138,335,136,347,124,351,122,355,116,357,106,363,100,369,98,375,94,377
%N A117128 Recamán transform of primes (another version): a(0)=1; for n>0, a(n) = a(n-1) - prime(n) if that number is positive and not already in the sequence, otherwise a(n) = a(n-1) + prime(n).
%C A117128 Differs from Cald's sequence A006509 for first time at n=116 (or 117, depending on offset).
%H A117128 Reinhard Zumkeller, <a href="/A117128/b117128.txt">Table of n, a(n) for n = 0..10000</a>
%H A117128 <a href="/index/Rea#Recaman">Index entries for sequences related to Recamán's sequence</a>
%F A117128 a(n) = A064365(n) + 1. - _Thomas Ordowski_, Dec 05 2016
%p A117128 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;
%p A117128 M2:=2000; nmax:=M2;
%p A117128 for n from 1 to M2 do p:=ithprime(n); i:=a[n-1]-p; j:=a[n-1]+p;
%p A117128 if i >= 1 and have[i]=0 then a[n]:=i; have[i]:=1;
%p A117128 elif j <= M1 then a[n]:=j; have[j]:=1;
%p A117128 else nmax:=n-1; break; fi; od: [seq(a[n],n=0..M2)];
%t A117128 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 *)
%o A117128 (Haskell)
%o A117128 import Data.Set (singleton, notMember, insert)
%o A117128 a117128 n = a117128_list !! n
%o A117128 a117128_list = 1 : f 1 a000040_list (singleton 1) where
%o A117128    f x (p:ps) s | x' > 0 && x' `notMember` s = x' : f x' ps (insert x' s)
%o A117128                 | otherwise                  = xp : f xp ps (insert xp s)
%o A117128                 where x' = x - p; xp = x + p
%o A117128 -- _Reinhard Zumkeller_, Apr 26 2012
%o A117128 (Python)
%o A117128 from sympy import primerange, prime
%o A117128 def aupton(terms):
%o A117128   alst = [1]
%o A117128   for n, pn in enumerate(primerange(1, prime(terms)+1), start=1):
%o A117128     x = alst[-1] - pn
%o A117128     alst += [x if x > 0 and x not in alst else alst[-1] + pn]
%o A117128   return alst
%o A117128 print(aupton(61)) # _Michael S. Branicky_, May 30 2021
%Y A117128 Cf. A064365, A006509, A112877.
%K A117128 nonn
%O A117128 0,2
%A A117128 _N. J. A. Sloane_, Apr 20 2006