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.

A370951 First differences of A112877 (zero terms in Cald's sequence A006509).

Original entry on oeis.org

82, 182, 46, 94, 200, 430, 846, 1628, 2982, 5662, 10940, 17924, 34308, 65768, 125760, 240732, 460672, 883598, 1697502, 3268008, 6297778, 12152690, 23482980, 45422208, 87949242, 170465380, 330760622, 642315104, 1094147916, 2132023868, 4153355532, 8093060816, 15777058876
Offset: 1

Views

Author

N. J. A. Sloane, Mar 07 2024

Keywords

Comments

The terms essentially double at each step. The ratios of successive terms are 2.219512195, 0.2527472527, 2.043478261, 2.127659574, 2.150000000, 1.967441860, 1.924349882, 1.831695332, 1.898725687, 1.932179442, 1.638391225, 1.914081678, 1.916987292, 1.912176134, 1.914217557, 1.913630095, 1.918063177, 1.921124765, 1.925186539, 1.927099934, 1.929679007, 1.932327740, 1.934260814, 1.936260826, 1.938224550, 1.940338983, 1.941933414, 1.703444165, 1.948570058, 1.948081161, 1.948559605, 1.949455124...

Crossrefs

Programs

  • Mathematica
    nn = 2^20; c[_] := False; a[1] = j = 1; c[1] = True;
    Differences@ Monitor[Reap[
        Do[p = Prime[n - 1];
         If[And[# > 0, ! c[#]], k = #,
            If[c[#], k = 0; Sow[n], k = #] &[j + p]] &[j - p];
    Set[{c[k], j}, {True, k}], {n, 2, nn}]][[-1, 1]], n] (* Michael De Vlieger, Mar 07 2024 *)
  • Python
    from itertools import count, islice
    from sympy import nextprime
    def A370951_gen(): # generator of terms
        a, aset, p, q = 1, {1}, 2, 0
        for c in count(2):
            if (b:=a-p) > 0 and b not in aset:
                a = b
            elif (b:=a+p) not in aset:
                a = b
            else:
                a = 0
                if q:
                    yield c-q
                q = c
            aset.add(a)
            p = nextprime(p)
    A370951_list = list(islice(A370951_gen(),10)) # Chai Wah Wu, Mar 07 2024

Extensions

a(29)-a(33) from Martin Ehrenstein, Mar 07 2024

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

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

A117129 Primes not occurring as |differences| in Cald's sequence A006509.

Original entry on oeis.org

641, 1213, 2617, 2957, 3727, 5443, 9283, 17359, 33829, 66173, 131303, 264763, 494743, 957547, 1888157, 3753647, 7490797, 14961157, 29899357, 59773871, 119551489, 239106347, 478234723, 956607929, 1913366111, 3826828409, 7653840367, 15308666783, 30619196381, 57415599151
Offset: 1

Views

Author

N. J. A. Sloane, Apr 20 2006

Keywords

Comments

In other words, primes that do not occur as absolute values of differences of successive terms in Cald's sequence A006509.

Crossrefs

Programs

  • Python
    from itertools import count, islice
    from sympy import nextprime
    def A117129_gen(): # generator of terms
        a, aset, p = 1, {1}, 2
        for c in count(2):
            if (b:=a-p) > 0 and b not in aset:
                a = b
            elif (b:=a+p) not in aset:
                a = b
            else:
                a = 0
                yield p
            aset.add(a)
            p = nextprime(p)
    A117129_list =  list(islice(A117129_gen(),10)) # Chai Wah Wu, Mar 04 2024

Formula

a(n) = prime(A112877(n) - 1).

Extensions

a(19)-a(26) from Donovan Johnson, Feb 18 2010
a(27)-a(29) from Chai Wah Wu, Mar 04 2024
a(30) from Chai Wah Wu, Mar 10 2024

A112878 A100298(n) = 0.

Original entry on oeis.org

14, 34, 35, 41, 42, 56, 92, 100, 124, 132, 133, 134, 135, 153, 167, 204, 216, 217, 218, 236, 261, 269, 283, 295, 330, 342, 369, 373, 392, 443, 464, 480, 488, 521, 587, 599, 634, 648, 688, 714, 723, 742, 786, 814, 815, 816, 817, 818, 819, 820, 821, 829, 833
Offset: 1

Views

Author

Klaus Brockhaus, Oct 24 2005

Keywords

Comments

A100298 is similar to Cald's sequence A006509, where zeros are much less frequent (cf. A112877).

Examples

			A100298(14) = 0 and A100298(k) > 0 for k < 14, so a(1) = 14.
		

Crossrefs

Showing 1-5 of 5 results.