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-10 of 18 results. Next

A030141 Numbers in which parity of the decimal digits alternates.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 21, 23, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 45, 47, 49, 50, 52, 54, 56, 58, 61, 63, 65, 67, 69, 70, 72, 74, 76, 78, 81, 83, 85, 87, 89, 90, 92, 94, 96, 98, 101, 103, 105, 107, 109, 121, 123, 125, 127, 129
Offset: 1

Views

Author

Keywords

Comments

An alternating integer is a positive integer for which, in base-10, the parity of its digits alternates.
The number of terms < 10^n (n>=0): 1, 10, 55, 280, 1405, 7030, 35155, ..., . - Robert G. Wilson v, Apr 01 2011
The number of terms between 10^n and 10^(n+1) is 9 * 5^n for n>=0. For n>=0, number of terms < 10^n is 1 + 9 * (5^n-1)/4. - Franklin T. Adams-Watters, Apr 01 2011
A228710(a(n)) = 1. - Reinhard Zumkeller, Aug 31 2013

Examples

			121 is alternating and in the sequence because its consecutive digits are odd-even-odd, 1 being odd and 2 even. Of course, 1234567890 is also alternating.
		

Crossrefs

Programs

  • Haskell
    a030141 n = a030141_list !! (n-1)
    a030141_list = filter ((== 1) . a228710) [0..]
    -- Reinhard Zumkeller, Aug 31 2013
    
  • Mathematica
    fQ[n_] := Block[{m = Mod[ IntegerDigits@ n, 2]}, m == Split[m, UnsameQ][[1]]]; Select[ Range[0, 130], fQ] (* Robert G. Wilson v, Apr 01 2011 *)
    Select[Range[0,150],FreeQ[Differences[Boole[EvenQ[IntegerDigits[#]]]],0]&] (* Harvey P. Dale, Jul 19 2025 *)
  • PARI
    is(n,d=digits(n))=for(i=2,#d, if((d[i]-d[i-1])%2==0, return(0))); 1 \\ Charles R Greathouse IV, Jul 08 2022
    
  • Python
    from itertools import count
    def A030141_gen(startvalue=0): # generator of terms >= startvalue
        return filter(lambda n:all(int(a)+int(b)&1 for a, b in zip(str(n),str(n)[1:])),count(max(startvalue,0)))
    A030141_list = list(islice(A030141_gen(),30)) # Chai Wah Wu, Jul 12 2022
    
  • Python
    from itertools import chain, count, islice
    def altgen(seed, digits):
        allowed = "02468" if seed in "13579" else "13579"
        if digits == 1: yield from allowed; return
        for f in allowed: yield from (f + r for r in altgen(f, digits-1))
    def agen(): yield from chain(range(10), (int(f+r) for d in count(2) for f in "123456789" for r in altgen(f, d-1)))
    print(list(islice(agen(), 65))) # Michael S. Branicky, Jul 12 2022

Extensions

Offset corrected by Reinhard Zumkeller, Aug 31 2013

A030152 Squares in which parity of digits alternates.

Original entry on oeis.org

0, 1, 4, 9, 16, 25, 36, 49, 81, 121, 169, 256, 361, 529, 676, 729, 961, 1296, 4761, 5476, 6561, 7056, 9216, 12321, 12769, 14161, 16129, 18769, 32761, 34969, 41616, 56169, 69696, 72361, 74529, 76729, 78961, 87616, 96721, 147456, 163216, 181476, 212521
Offset: 1

Views

Author

Keywords

Examples

			1296 is a term as 1, 2, 9 and 6 have odd and even parity alternately.
		

Crossrefs

Programs

  • Haskell
    a030152 n = a030152_list !! (n-1)
    a030152_list = filter ((== 1) . a228710) a000290_list
    -- Reinhard Zumkeller, Aug 31 2013
  • Maple
    i := 0:for a from 1 to 1000 do b := a^2:g := ceil(log(b+1)/log(10)):iss := true:for j from 1 to g-1 do if((b mod 2)=1) then if((floor(b/10^j) mod 2)=((-1)^(j+1)+1)/2) then iss := false:end if:else if((floor(b/10^j) mod 2)=((-1)^j+1)/2) then iss := false:end if:end if:end do: if(iss=true) then i := i+1:c[i] := b:end if:end do:q := seq(c[k],k=1..i-1); # Sascha Kurz, Mar 23 2002
  • Mathematica
    altQ[n_] := n < 10 || Union[Total /@ Partition[ Mod[ IntegerDigits@n, 2], 2, 1]] == {1}; Select[ Range[0, 500]^2, altQ[#] &] (* Giovanni Resta, Aug 16 2018 *)

Formula

A010052(a(n)) * A228710(a(n)) = 1. - Reinhard Zumkeller, Aug 31 2013

Extensions

Edited by N. J. A. Sloane, Aug 31 2009 at the suggestion of R. J. Mathar
Offset corrected by Reinhard Zumkeller, Aug 31 2013

A068876 Smallest n-digit prime with property that digits alternate in parity.

Original entry on oeis.org

2, 23, 101, 2129, 10103, 210101, 1010129, 21010127, 101010167, 2101010147, 10101010163, 210101010187, 1010101010341, 21010101010147, 101010101010323, 2101010101010141, 10101010101010141, 210101010101010323, 1010101010101010143
Offset: 1

Views

Author

Amarnath Murthy, Mar 19 2002

Keywords

Examples

			a(4) = 2129 as 2, 1, 2 and 9 have even and odd parity alternately.
		

Crossrefs

Programs

  • Maple
    alp:= proc(n) local L,d;
    L:= convert(n,base,10);
    d:= nops(L);
    if d::even then L:= L + map(op, [[0,1]$(d/2)]) else L:= L + map(op, [[0,1]$((d-1)/2),[0]]) fi;
    nops(convert(L mod 2, set))=1
    end proc:
    f:= proc(d) local s;
      if d::even then s:= 2*10^(d-1)+(10^d-1)/99-1
      else s:= (10^(d+1)-1)/99-1
      fi;
      do s:= nextprime(s);
         if alp(s) then return s fi
      od
    end proc:
    seq(f(d),d=1..20); # Robert Israel, Aug 14 2018
  • Mathematica
    fQ[n_] := Block[{m = Mod[ IntegerDigits@ n, 2]}, m == Split[m, UnsameQ][[1]]]; f[n_] := Block[{c = 1 + 100 (100^Ceiling[n/2 - 1] - 1)/99, k}, k = If[ OddQ@ n, c, 2*10^(n - 1) + c]; k = NextPrime[k - 1]; While[ !fQ@ k, k = NextPrime@ k]; k]; Array[f, 21] (* Robert G. Wilson v, Apr 01 2011 *)
  • Sage
    concat = lambda x: Integer(''.join(map(str,x)),base=10)
    def A068876(n):
        dd = {0:range(0,10,2), 1: range(1,10,2)}
        for d0 in [1..9]:
            if n % 2 == 0 and d0 % 2 == 1: continue # optimization
            ds = [dd[(d0+1+i) % 2] for i in range(n-1)]
            for dr in cartesian_product(ds):
                c = concat([d0]+dr)
                if is_prime(c): return c  # D. S. McNeil, Apr 02 2011

Extensions

a(9)-a(13) corrected and a(14)-a(19) from Donovan Johnson, Apr 01 2011

A030147 Palindromes in which parity of digits alternates.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 101, 121, 141, 161, 181, 212, 232, 252, 272, 292, 303, 323, 343, 363, 383, 414, 434, 454, 474, 494, 505, 525, 545, 565, 585, 616, 636, 656, 676, 696, 707, 727, 747, 767, 787, 818, 838, 858, 878, 898, 909, 929, 949
Offset: 1

Views

Author

Keywords

Comments

All terms have an odd number of digits. - Alonso del Arte, Jan 31 2020

Crossrefs

Intersection of A002113 and A030141.
Subsequence of A001633.

Programs

  • Haskell
    a030147 n = a030147_list !! (n-1)
    a030147_list = filter ((== 1) . a228710) a002113_list
    -- Reinhard Zumkeller, Aug 31 2013
    
  • Mathematica
    palQ[n_, b_:10] := (IntegerDigits[n, b] == Reverse[IntegerDigits[n, b]]); alternParQ[n_, b_:10] := (Union[BlockMap[Xor @@ # &, OddQ[IntegerDigits[n, b]], 2, 1]] == {True}); Join[Range[0, 9], Select[Range[1000], palQ[#] && alternParQ[#] &]] (* Alonso del Arte, Feb 02 2020 *)
    Join[Range[0,9],Select[Range[100000],PalindromeQ[#]&&Union[Total/@Partition[Boole[ EvenQ[ IntegerDigits[ #]]],2,1]] =={1}&]] (* Harvey P. Dale, Jul 04 2023 *)
  • Scala
    def isPal(n: Int) = (n.toString == n.toString.reverse)
    def alternsPar(n: Int): Boolean = {
      val dPars = Integer.toString(n).toList.map(_ % 2 == 0)
      val scanPars = (dPars zip dPars.tail).map{ case (x, y) => x ^ y }
      scanPars.toSet == Set(true)
    }
    (0 to 9) ++: (10 to 999).filter(isPal).filter(alternsPar) // Alonso del Arte, Feb 02 2020

Formula

A136522(a(n)) * A228710(a(n)) = 1. - Reinhard Zumkeller, Aug 31 2013

A343590 Undulating alternating primes.

Original entry on oeis.org

2, 3, 5, 7, 23, 29, 41, 43, 47, 61, 67, 83, 89, 101, 103, 107, 109, 163, 181, 307, 383, 503, 509, 523, 547, 563, 587, 701, 709, 727, 769, 787, 907, 929, 947, 967, 2141, 2143, 2161, 2309, 2503, 2549, 2707, 2729, 2749, 2767, 2903, 2909, 2927, 2969, 4363, 4507, 4523, 4547, 4549, 4703
Offset: 1

Views

Author

Bernard Schott, Apr 21 2021

Keywords

Comments

Equivalently, primes in which the value of the digits alternately rises or falls (undulating, A059168) and in which the parity of the digits changes in turns (alternating, A030144).
The first 17 terms are the same as A030144; then a(18) = 163 while A030144(18) = 127.

Examples

			2143 is a term as it is prime, digits 2, 1, 4 and 3 have even and odd parity alternately, and also alternately fall and rise.
		

Crossrefs

Intersection of A030144 and A059168.
A343591 is a subsequence.

Programs

  • Mathematica
    q[n_] := PrimeQ[n] && AllTrue[Differences[Sign @ Differences[(d = IntegerDigits[n])]], # != 0 &] && AllTrue[Differences @ Mod[d, 2], # != 0 &]; Select[Range[5000], q] (* Amiram Eldar, Apr 21 2021 *)
  • Python
    from sympy import sieve
    def sign(n): return (n > 0) - (n < 0)
    def ok(p):
      if p < 10: return True
      s = str(p)
      t = set(sign(int(s[i])%2-int(s[i-1])%2)*(-1)**i for i in range(1, len(s)))
      t2 = set(sign(int(s[i])-int(s[i-1]))*(-1)**i for i in range(1, len(s)))
      return (t == {1} or t == {-1}) and (t2 == {1} or t2 == {-1})
    def aupto(limit): return [p for p in sieve.primerange(1, limit+1) if ok(p)]
    print(aupto(4703)) # Michael S. Branicky, Apr 21 2021
    
  • Python
    from sympy import isprime
    def f(w,dir):
        if dir == 1:
            for s in w:
                for t in range(int(s[-1])+1,10,2):
                    yield s+str(t)
        else:
            for s in w:
                for t in range(1-int(s[-1])%2,int(s[-1]),2):
                    yield s+str(t)
    A343590_list = []
    for l in range(5):
        for d in '123456789':
            x = d
            for i in range(1,l+1):
                x = f(x,(-1)**i)
            A343590_list.extend([int(p) for p in x if isprime(int(p))])
            if l > 0:
                y = d
                for i in range(1,l+1):
                    y = f(y,(-1)**(i+1))
                A343590_list.extend([int(p) for p in y if isprime(int(p))]) # Chai Wah Wu, Apr 25 2021

A323578 Primes with distinct digits for which parity of digits alternates.

Original entry on oeis.org

2, 3, 5, 7, 23, 29, 41, 43, 47, 61, 67, 83, 89, 103, 107, 109, 127, 149, 163, 167, 307, 347, 349, 367, 389, 503, 509, 521, 523, 541, 547, 563, 569, 587, 701, 709, 743, 761, 769, 907, 941, 947, 967, 983, 2143, 2309
Offset: 1

Views

Author

Bernard Schott, Jan 18 2019

Keywords

Comments

There are 4426 terms (found by David A. Corneth) in this sequence, which is a subsequence of A030144.
The largest prime of this sequence is 987654103 which is also the largest prime with distinct digits in A029743.

Examples

			2143 is a term as 2, 1, 4 and 3 have even and odd parity alternately and these four digits are all distinct.
		

Crossrefs

Intersection of A030144 and A029743.

Programs

  • Mathematica
    {2}~Join~Select[Prime@ Range@ 350, And[Max@ Tally[#][[All, -1]] == 1, AllTrue[#[[Range[2, Length[#], 2] ]], EvenQ], AllTrue[#[[Range[1, Length[#], 2] ]], OddQ]] &@ Reverse@ IntegerDigits@ # &] (* Michael De Vlieger, Jan 19 2019 *)
  • PARI
    allTerms() = {my(res = List([2])); c = vector(10); odd = [1, 3, 5, 7, 9]; even = [0, 2, 4, 6, 8]; for(i = 0, 119, pi = numtoperm(5, i); vi = vector(5, k, odd[pi[k]]); for(j = 0, 119, pj = numtoperm(5, j); vj = vector(5, k, even[pj[k]]); for(m = 1, 5, c[2*m] = vi[m]; c[2*m - 1] = vj[m]; ); cv = fromdigits(c); for(m = 1, 10, if(isprime(cv % 10^m), listput(res, cv % 10^m); ) ) ) ); listsort(res, 1); res } \\ David A. Corneth, Jan 18 2019

A343675 Undulating alternating palindromic primes.

Original entry on oeis.org

2, 3, 5, 7, 101, 181, 383, 727, 787, 929, 10301, 10501, 14341, 16361, 16561, 18181, 30103, 30703, 32323, 36563, 38183, 38783, 70507, 72727, 74747, 78787, 90709, 94949, 96769, 1074701, 1092901, 1212121, 1218121, 1412141, 1616161, 1658561, 1856581, 1878781, 3072703
Offset: 1

Views

Author

Chai Wah Wu, Apr 25 2021

Keywords

Comments

All terms have an odd number of decimal digits.
For n > 3, a(n) is odd and not divisible by 5.
Intersection of A002385, A030144 and A059168.
Subsequence of A343590.

Examples

			16361 is a term as it is a palindromic prime, the digits 1, 6, 3, 6 and 1 have odd and even parity alternately, and also alternately rise and fall.
		

Crossrefs

Programs

  • Mathematica
    Union@Flatten[{{2,3,5,7},Array[Select[FromDigits/@Riffle@@@Tuples[{Tuples[{1,3,5,7,9},#],Tuples[{0,2,4,6,8},#-1]}],(s=Union@Partition[Sign@Differences@IntegerDigits@#,2];(s=={{1,-1}}||s=={{-1,1}})&&PrimeQ@#&&PalindromeQ@#)&]&,4]}] (* Giorgos Kalogeropoulos, Apr 26 2021 *)
  • Python
    from sympy import isprime
    def f(w):
        for s in w:
            for t in range(int(s[-1])+1,10,2):
                yield s+str(t)
    def g(w):
        for s in w:
            for t in range(1-int(s[-1])%2,int(s[-1]),2):
                yield s+str(t)
    A343675_list = [2,3,5,7]
    for l in range(1,9):
        for d in '1379':
            x = d
            for i in range(1,l+1):
                x = g(x) if i % 2 else f(x)
            A343675_list.extend([int(p+p[-2::-1]) for p in x if isprime(int(p+p[-2::-1]))])
            y = d
            for i in range(1,l+1):
                y = f(y) if i % 2 else g(y)
            A343675_list.extend([int(p+p[-2::-1]) for p in y if isprime(int(p+p[-2::-1]))])

A030145 Primes such that in p^2 the parity of digits alternates.

Original entry on oeis.org

2, 3, 5, 7, 11, 13, 19, 23, 31, 113, 127, 137, 181, 269, 277, 281, 311, 461, 463, 661, 673, 677, 1019, 1277, 1361, 1973, 2287, 2339, 2377, 2411, 2423, 2689, 2731, 4673, 5023, 5081, 5261, 6563, 6577, 8311, 9013, 9437, 9439, 10181, 10463
Offset: 1

Views

Author

Keywords

Crossrefs

Programs

  • Mathematica
    id[n_]:=IntegerDigits[n]; t={}; Do[p=Prime[n]; If[Length[id[p]]==1,AppendTo[t,p], If[Union[Abs[Differences[Boole/@EvenQ[id[p^2]]]]]=={1}, AppendTo[t,p]]], {n,1300}]; t (* Jayanta Basu, May 07 2013 *)
    pdaQ[n_]:=FreeQ[Differences[Boole[EvenQ[IntegerDigits[n^2]]]],0]; Select[ Prime[ Range[1300]],pdaQ] (* Harvey P. Dale, Jul 30 2019 *)

Formula

a(n)^2 = A030146(n). - Giovanni Resta, Aug 16 2018

Extensions

Offset corrected by Giovanni Resta, Aug 16 2018

A030150 Palindromic primes in which parity of digits alternates.

Original entry on oeis.org

2, 3, 5, 7, 101, 181, 383, 727, 787, 929, 10301, 10501, 12721, 14341, 14741, 16361, 16561, 18181, 30103, 30703, 32323, 34543, 36563, 38183, 38783, 70507, 72727, 74747, 76367, 78787, 90709, 94349, 94949, 96769, 98389, 1074701
Offset: 1

Views

Author

Keywords

Crossrefs

Programs

  • Mathematica
    altQ[n_] := n < 10 || Union[Total /@ Partition[ Mod[ IntegerDigits@ n, 2], 2, 1]] == {1}; palQ[n_] := Block[{d = IntegerDigits[n]}, d == Reverse@ d]; Select[ Prime@ Range@ 10000, palQ[#] && altQ[#] &] (* Giovanni Resta, Aug 16 2018 *)
    Join[{2,3,5,7},Select[Prime[Range[85000]],PalindromeQ[#]&&Union[Total/@Partition[ Boole[ EvenQ/@IntegerDigits[#]],2,1]]=={1}&]] (* Harvey P. Dale, Jul 10 2023 *)

A068877 Largest n-digit prime with property that digits alternate in parity.

Original entry on oeis.org

7, 89, 983, 8969, 98981, 898987, 9898921, 89898983, 989898989, 8989898969, 98989898981, 898989898987, 9898989898901, 89898989898967, 989898989898943, 8989898989898969, 98989898989898981, 898989898989898943, 9898989898989898789
Offset: 1

Views

Author

Amarnath Murthy, Mar 19 2002

Keywords

Examples

			a(4) = 8969 as 8, 9, 6 and 9 have even and odd parity alternately.
		

Crossrefs

Programs

  • Sage
    concat = lambda x: Integer(''.join(map(str,x)),base=10)
    def A068877(n):
        dd = {0:range(0,10,2)[::-1], 1: range(1,10,2)[::-1]}
        for d0 in [1..9][::-1]:
            if n % 2 == 0 and d0 % 2 == 1: continue # optimization
            ds = [dd[(d0+1+i) % 2] for i in range(n-1)]
            for dr in cartesian_product(ds):
                c = concat([d0]+dr)
                if is_prime(c): return c  # [D. S. McNeil, Apr 02 2011]

Extensions

a(15)-a(19) from Donovan Johnson, Apr 01 2011
Showing 1-10 of 18 results. Next