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.

Showing 1-5 of 5 results.

A006509 Cald's sequence: a(n+1) = a(n) - prime(n) if that value is positive and new, otherwise a(n) + prime(n) if new, otherwise 0; start with a(1)=1.

Original entry on oeis.org

1, 3, 6, 11, 4, 15, 2, 19, 38, 61, 32, 63, 26, 67, 24, 71, 18, 77, 16, 83, 12, 85, 164, 81, 170, 73, 174, 277, 384, 275, 162, 35, 166, 29, 168, 317, 468, 311, 148, 315, 142, 321, 140, 331, 138, 335, 136, 347, 124, 351, 122, 355, 116, 357, 106, 363, 100, 369, 98, 375, 94, 377, 84, 391, 80, 393, 76, 407, 70, 417, 68, 421, 62, 429, 56, 435, 52, 441, 44, 445, 36, 455, 34, 465, 898, 459, 902, 453, 910, 449, 912, 1379, 900, 413, 904, 405, 908, 399, 920, 397, 938, 1485, 928, 365, 934, 1505, 2082, 1495, 2088, 1489, 888, 281, 894, 1511, 892, 261, 0, 643, 1290, 637, 1296, 635, 1308, 631, 1314, 623, 1324, 615, 1334, 607, 1340
Offset: 1

Views

Author

Keywords

Comments

The differences between this sequence and A117128 ("Recamán transform of primes") are (i) the offset (0 there) and (ii) there the sum is used in the second case whether it has already occurred or not (so duplicates occur), while here a(n+1) = 0 if the sum already occurred (so there are no duplicates apart from the zeros). - M. F. Hasler, Mar 06 2024

References

  • F. Cald, Problem 356, Franciscan order, J. Rec. Math., 7 (No. 4, 1974), 318; 10 (No. 1, 1977-78), 62-64.
  • "Cald's Sequence", Popular Computing (Calabasas, CA), Vol. 4 (No. 41, Aug 1976), pp. 16-17.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Cf. A005132, A093903, A112877 & A370951 (indices of zeros).
A111338 gives (conjecturally) the terms of the present sequence sorted into increasing order, and A111339 gives (conjecturally) the numbers missing from the present sequence.

Programs

  • Haskell
    a006509 n = a006509_list !! (n-1)
    a006509_list = 1 : f [1] a000040_list where
       f xs'@(x:_) (p:ps) | x' > 0 && x' `notElem` xs = x' : f (x':xs) ps
                          | x'' `notElem` xs          = x'' : f (x'':xs) ps
                          | otherwise                 = 0 : f (0:xs) ps
                          where x' = x - p; x'' = x + p
    -- Reinhard Zumkeller, Oct 17 2011
    
  • Maple
    M1:=500000; a:=array(0..M1); have:=array(0..M1); a[0]:=1;
    for n from 0 to M1 do have[n]:=0; od: have[0]:=1; 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 and have[j]=0 then a[n]:=j; have[j]:=1;
    elif j <= M1 then a[n]:=0; else nmax:=n-1; break; fi; od:
    # To get A006509:
    [seq(a[n],n=0..M2)];
    # To get A112877 (off by 1 because of different offset in A006509):
    zzz:=[]; for n from 0 to nmax do if a[n]=0 then zzz:=[op(zzz),n]; fi; od: [seq(zzz[i],i=1..nops(zzz))];
  • Mathematica
    lst = {1}; f := Block[{b = Last@lst, p = Prime@ Length@lst}, If[b > p && !MemberQ[lst, b - p], AppendTo[lst, b - p], If[ !MemberQ[lst, b + p], AppendTo[lst, b + p], AppendTo[lst, 0]] ]]; Do[f, {n, 60}]; lst (* Robert G. Wilson v, Apr 25 2006 *)
  • PARI
    A006509_upto(N, U=0)=vector(N,i, N=if(i>1, my(p=prime(i-1)); if( N>p && !bittest(U,N-p), N-p, !bittest(U, N+p), N+p), 1); N && U += 1 << N; N) \\ M. F. Hasler, Mar 06 2024
  • Python
    from sympy import primerange, prime
    def aupton(terms):
      alst = [1]
      for n, pn in enumerate(primerange(1, prime(terms)+1), start=1):
        x, y = alst[-1] - pn, alst[-1] + pn
        if x > 0 and x not in alst: alst.append(x)
        elif y > 0 and y not in alst: alst.append(y)
        else: alst.append(0)
      return alst
    print(aupton(130)) # Michael S. Branicky, May 30 2021
    
  • Python
    from sympy import nextprime
    from itertools import islice
    def agen(): # generator of terms
        pn, an, aset = 2, 1, {1}
        while True:
            yield an
            an = m if (m:=an-pn) > 0 and m not in aset else p if (p:=an+pn) not in aset else 0
            aset.add(an)
            pn = nextprime(pn)
    print(list(islice(agen(), 131))) # Michael S. Branicky, Mar 07 2024
    

Extensions

More terms from Larry Reeves (larryr(AT)acm.org), Jul 20 2001
Many more terms added by N. J. A. Sloane, Apr 20 2006, to show difference from A117128.
Entry revised by N. J. A. Sloane, Mar 06 2024

A022831 a(n) = c(1)p(1) + ... + c(n)p(n), where c(i) = 1 if a(i-1) <= p(i) and c(i) = -1 if a(i-1) > p(i), for i = 1,...,n (p(i) = primes).

Original entry on oeis.org

2, 5, 10, 3, 14, 1, 18, 37, 14, 43, 12, 49, 8, 51, 4, 57, 116, 55, 122, 51, 124, 45, 128, 39, 136, 35, 138, 31, 140, 27, 154, 23, 160, 21, 170, 19, 176, 13, 180, 7, 186, 5, 196, 3, 200, 1, 212, 435, 208, 437, 204, 443, 202, 453, 196, 459, 190, 461, 184
Offset: 1

Views

Author

Keywords

Comments

a(n) <= 2*prime(n). Conjecture: every number occurs in the sequence at most finitely many times. - Thomas Ordowski, Dec 03 2016

Examples

			a(1)=2, a(2)=2+3=5, a(3)=5+5=10, a(4)=10-7=3, a(5)=3+11=14, a(6)=14-13=1, ...
		

Crossrefs

Cf. A064365.

Programs

  • Haskell
    a022831 n = a022831_list !! n
    a022831_list = 2 : f 2 (tail a000040_list) where
       f x (p:ps) | x' > 0    = x' : f x' ps
                  | otherwise = xp : f xp ps where x' = x - p; xp = x + p
    -- Reinhard Zumkeller, Apr 26 2012

Extensions

Name corrected by Sean A. Irvine, May 22 2019

A053461 a(0) = 0; a(n) = a(n-1) - n^2 if positive and new, otherwise a(n) = a(n-1) + n^2.

Original entry on oeis.org

0, 1, 5, 14, 30, 55, 19, 68, 4, 85, 185, 64, 208, 39, 235, 10, 266, 555, 231, 592, 192, 633, 149, 678, 102, 727, 51, 780, 1564, 723, 1623, 662, 1686, 597, 1753, 528, 1824, 455, 1899, 378, 1978, 297, 2061, 212, 2148, 123, 2239, 4448, 2144, 4545
Offset: 0

Views

Author

N. J. A. Sloane, Feb 09 2002

Keywords

Comments

'Recamán transform' (see A005132) of the squares.

Crossrefs

Cf. A076042 ('Easy Recamán transform' of the squares), A064365 ('Recamán transform' of the primes).

Programs

  • Mathematica
    a = {0, 1}; Do[If[a[[-1]] - n^2 >= 0 && Position[a, a[[-1]] - n^2] == {}, a = Append[a, a[[-1]] - n^2], a = Append[a, a[[-1]] + n^2]], {n, 2, 49}]; Print[a] (* Samuel Harkness, Sep 20 2022 *)
  • PARI
    lista(nn) = {my(va = vector(nn)); va[1] = 1; my(sa = Set(va)); for (n=2, nn, my(x = va[n-1] - n^2); if ((x>0) && !setsearch(sa, x), va[n] = x, va[n] =  va[n-1] + n^2); sa = Set(va);); concat(0, va);} \\ Michel Marcus, Sep 26 2022

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).

Original entry on oeis.org

1, 3, 6, 11, 4, 15, 2, 19, 38, 61, 32, 63, 26, 67, 24, 71, 18, 77, 16, 83, 12, 85, 164, 81, 170, 73, 174, 277, 384, 275, 162, 35, 166, 29, 168, 317, 468, 311, 148, 315, 142, 321, 140, 331, 138, 335, 136, 347, 124, 351, 122, 355, 116, 357, 106, 363, 100, 369, 98, 375, 94, 377
Offset: 0

Views

Author

N. J. A. Sloane, Apr 20 2006

Keywords

Comments

Differs from Cald's sequence A006509 for first time at n=116 (or 117, depending on offset).

Crossrefs

Programs

  • 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
    
  • 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 *)
  • 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

Formula

a(n) = A064365(n) + 1. - Thomas Ordowski, Dec 05 2016

A128204 a(0) = 0; a(n) = a(n-1) - (2n-1) if that number is positive and not already in the sequence, otherwise a(n) = a(n-1) + (2n-1).

Original entry on oeis.org

0, 1, 4, 9, 2, 11, 22, 35, 20, 3, 22, 43, 66, 41, 14, 43, 12, 45, 10, 47, 8, 49, 6, 51, 98, 147, 96, 149, 94, 37, 96, 157, 220, 155, 88, 19, 90, 17, 92, 15, 94, 13, 96, 181, 268, 179, 270, 177, 82, 179, 80, 181, 78, 183, 76, 185, 74, 187, 72, 189, 70, 191, 68, 193, 320
Offset: 0

Views

Author

Nick Hobson, Feb 19 2007

Keywords

Comments

'Recamán transform' (see A005132) of the odd numbers.

Examples

			Consider n=7. We have a(6)=22 and try to subtract 13, the 7th odd number. The result, 9, is certainly positive, but we cannot use it because 9 is already in the sequence. So we must add 13 instead, getting a(7) = 22 + 13 = 35.
		

Crossrefs

Programs

  • PARI
    A128204(N,s/*=1 to print all terms*/)={my(a=0,u=0);  for( n=1,N, s&print1(a","); u=bitor(u,2^a+=if(a<2*n || bittest(u,a+1-2*n), 2*n-1,1-2*n)));a} \\ M. F. Hasler, Mar 07 2012
Showing 1-5 of 5 results.