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 16 results. Next

A179239 Permutation classes of integers, each identified by its smallest member.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 44, 45, 46, 47, 48, 49, 50, 55, 56, 57, 58, 59, 60, 66, 67, 68, 69, 70, 77, 78, 79, 80, 88, 89, 90, 99, 100, 101, 102, 103
Offset: 0

Views

Author

Aaron Dunigan AtLee, Jul 04 2010

Keywords

Comments

Let the "permutation set" of a positive integer n be the set of all integers formed by permuting the digits of n. Two integers are "permutationally congruent" if they generate the same permutation set. A "permutation class" is a set of all permutationally congruent integers. This sequence lists each permutation class, identified by its smallest member.
These are also the positive integers in order, omitting any d-digit number n if a previously listed d-digit number is a permutation of the digits of n.
Range of A328447: smallest representative of the equivalence class of all numbers having the same digits up to permutation. Equivalently: Numbers with digits in nondecreasing order, except that the smallest nonzero digit must precede the zero digits. This sequence is useful when considering functions which depend only on the digits of n, e.g., the number of primes contained in n, cf. A039993, A039999, A075053 and the records therein, A072857 (primeval numbers) and A076497, resp. A239196 and A239197, etc. - M. F. Hasler, Oct 18 2019

Examples

			The permutation set of 24 is {24, 42}, and this is the equivalence class modulo permutations of both of them, so 24 is listed, but 42 is not.
The permutation set of 30 is {3, 30}, but 3 is not in the same permutation class as 30 since 30 cannot be obtained by permuting digits of 3. Therefore 30 is listed separately from 3.
The numbers 89 and 98 are also permutationally congruent and form a permutation class, so only the smaller one is listed.
		

Crossrefs

A variant of A009994.
Cf. A047726, A035927 (Number of distinct n-digit numbers up to permutations of digits).
Cf. A004186, A328447: largest & smallest representative of the class of n.

Programs

  • Mathematica
    maxTerm = 103; (*maxTerm is the greatest term you wish to see*) permutationSet[n_Integer] := FromDigits /@ Permutations[IntegerDigits[n]]; permutationCongruentQ[x_Integer, y_Integer] := Sort[permutationSet[x]] == Sort[permutationSet[y]]; DeleteDuplicates[Range[maxTerm], permutationCongruentQ]
    f[n_] := Block[{a = {0}, b = {DigitCount[0]}, i, w}, Do[w = DigitCount@ i; AppendTo[b, w]; If[! MemberQ[Most@ b, w], AppendTo[a, i]], {i, n}]; Rest@ a]; f@ 103 (* or faster: *)
    Select[Range@ 103, LessEqual @@ IntegerDigits@ # || And[Take[IntegerDigits@ #, Last@ DigitCount@ # + 1] == Reverse@ Take[Sort@ IntegerDigits@ #, Last@ DigitCount@ # + 1], LessEqual @@ DeleteCases[IntegerDigits@ #, d_ /; d == 0]] &] (* Michael De Vlieger, Jul 14 2015 *)
  • PARI
    is(n) = {my(d=digits(n),i); for(i=2,#d, if(d[i]!=0, d=vecextract(d,concat([1],vector(#d-i+1,j,i-1+j))); break));d==vecsort(d)||n/10^valuation(n,10)<10}
    \\given an element n, in base b, find the next element from the sequence.
    nxt(n,{b=10}) = {my(d = digits(n)); i = #d; while(i>0&&d[i]==b-1,i--); if(i>1, if(d[i]>0, d[i]++, d[i]=d[1];);for(j=i+1,#d,d[j]=d[i]), if(i==1, d[i]++;for(j=2,#d,d[j]=0), return(10^(#d))));sum(j=1,#d,d[j]*10^(#d-j))} \\ David A. Corneth, Apr 23 2016
    
  • PARI
    select( is_A179239(n)={n==A328447(n)}, [0..200]) \\ M. F. Hasler, Oct 18 2019
    
  • Python
    from itertools import count, chain, islice
    from sympy.utilities.iterables import combinations_with_replacement
    def A179239_gen(): # generator of terms
        return chain((0,),(int(a+''.join(b)) for l in count(1) for a in '123456789' for b in combinations_with_replacement('0'+''.join(str(d) for d in range(int(a),10)),l-1)))
    A179239_list = list(islice(A179239_gen(),31)) # Chai Wah Wu, Sep 13 2022

Extensions

Prefixed with a(0) = 0 by M. F. Hasler, Oct 18 2019

A039993 Number of different primes embedded in n.

Original entry on oeis.org

0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 3, 1, 1, 1, 3, 0, 1, 1, 1, 1, 3, 1, 2, 1, 2, 1, 2, 1, 3, 3, 1, 2, 3, 1, 4, 2, 1, 0, 1, 1, 2, 0, 1, 0, 2, 0, 0, 1, 1, 2, 3, 1, 1, 1, 2, 1, 2, 0, 1, 1, 1, 0, 1, 0, 2, 0, 0, 1, 3, 2, 4, 2, 2, 2, 1, 1, 3, 0, 0, 1, 2, 0, 1, 0, 1, 0, 1, 0, 1, 2, 1, 0, 2, 0, 3, 1, 0, 0, 2, 1, 4, 2, 1
Offset: 1

Views

Author

Keywords

Comments

a(n) counts (distinct) permuted subsequences of digits of n which denote primes.

Examples

			a(17) = 3 since we can obtain 7, 17 and 71. a(22) = 1, since we can get only one prime (in contrast, A075053(22) = 2).
a(1013) = 14 because the prime subsets derived from the digital permutations of 1013 are {3, 11, 13, 31, 101, 103, 113, 131, 311, 1013, 1031, 1103, 1301, 3011}.
		

Crossrefs

Different from A075053. For records see A072857, A076497. See also A134596, A134597.
Cf. A039999.

Programs

  • Mathematica
    Needs["DiscreteMath`Combinatorica`"]; f[n_] := Block[{a = Drop[ Sort[ Subsets[ IntegerDigits[n]]], 1], b = c = {}, k = 1, l}, l = Length[a] + 1; While[k < l, b = Append[b, Permutations[ a[[k]] ]]; k++ ]; b = Union[ Flatten[b, 1]]; l = Length[b] + 1; k = 1; While[k < l, c = Append[c, FromDigits[ b[[k]] ]]; k++ ]; Count[ PrimeQ[ Union[c]], True]]; Table[ f[n], {n, 1, 105}]
    Table[Count[Union[FromDigits/@(Flatten[Permutations/@Subsets[ IntegerDigits[ n]],1])],?PrimeQ],{n,110}] (* _Harvey P. Dale, Nov 29 2017 *)
  • PARI
    A039993(n)={my(S=[],D=vecsort(digits(n))); for(i=1,2^#D-1, forperm(vecextract(D,i),p, isprime(fromdigits(Vec(p)))||next; S=setunion(S,[fromdigits(Vec(p))]))); #S} \\ To avoid duplicate scan of identical subsets of digits, one could skip the corresponding range of indices i when a binary pattern ...10... is detected. - M. F. Hasler, Mar 08 2014, simplified Oct 15 2019
    
  • Python
    from itertools import permutations
    from sympy import isprime
    def a(n):
        l=list(str(n))
        L=[]
        for i in range(len(l)):
            L+=[int("".join(x)) for x in permutations(l, i + 1)]
        return len([i for i in set(L) if isprime(i)])
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 25 2017
    
  • Python
    from sympy.utilities.iterables import multiset_permutations
    from sympy import isprime
    def A039993(n): return sum(1 for l in range(1,len(str(n))+1) for a in multiset_permutations(str(n),size=l) if a[0] !='0' and isprime(int(''.join(a)))) # Chai Wah Wu, Sep 13 2022

Extensions

Edited by Robert G. Wilson v, Nov 25 2002
Keith link repaired by Charles R Greathouse IV, Aug 13 2009

A046810 Number of anagrams of n that are primes.

Original entry on oeis.org

0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 2, 1, 0, 1, 2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 0, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 2, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 2, 1, 0, 0, 1, 0, 1, 1, 0, 1, 2, 0
Offset: 1

Views

Author

Keywords

Comments

An anagram of a k-digit number is one of the k! permutations of the digits that does not begin with 0.

Examples

			107 has 2 prime anagrams: 107 and 701 (but not 017 or 071); so a(107) = 2.
		

Crossrefs

Programs

  • Haskell
    import Data.List (permutations, nub)
    a046810 n = length $ filter ((== 1) . a010051)
                       $ map read (nub $ filter ((> '0') . head)
                                                $ permutations $ show n)
    -- Reinhard Zumkeller, Aug 14 2011
    
  • Mathematica
    Table[Count[FromDigits/@Select[Permutations[IntegerDigits[n]], First[#] != 0&],?(PrimeQ[#]&)],{n,110}] (* _Harvey P. Dale, Aug 24 2011 *)
  • Python
    from sympy import isprime
    from itertools import permutations
    def a(n): return len(set(t for p in permutations(str(n)) if p[0]!="0" and isprime(t:=int("".join(p)))))
    print([a(n) for n in range(1, 106)]) # Michael S. Branicky, Feb 17 2024

A075053 Number of primes (counted with repetition) that can be formed by rearranging some or all of the digits of n.

Original entry on oeis.org

0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 3, 1, 1, 1, 3, 0, 1, 1, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 3, 3, 2, 2, 3, 1, 4, 2, 1, 0, 1, 1, 2, 0, 1, 0, 2, 0, 0, 1, 1, 2, 3, 1, 2, 1, 2, 1, 2, 0, 1, 1, 1, 0, 1, 0, 2, 0, 0, 1, 3, 2, 4, 2, 2, 2, 2, 1, 3, 0, 0, 1, 2, 0, 1, 0, 1, 0, 1, 0, 1, 2, 1, 0, 2, 0, 3, 1, 0, 0, 2, 1, 4, 2
Offset: 0

Views

Author

N. J. A. Sloane, Oct 12 2002

Keywords

Comments

"Counted with repetition" means that if the same prime can be obtained using different digits, then it is counted several times (e.g., 13 obtained from 113 using the 1st and 3rd digit or the 2nd and 3rd digit), but not so if it is obtained as different permutations of the same digits (e.g., a(11) = 1 because the identical permutation and the transposition (2,1) of the digits [1,1] both yield 11, but this does not count twice since the same digits are used). - M. F. Hasler, Mar 12 2014
See A039993 for the variant which counts only distinct primes, e.g., A039993(22) = 1, A039993(113) = 7. See A039999 for the variant which requires all digits to be used. - M. F. Hasler, Oct 14 2019

Examples

			From 13 we can obtain 3, 13 and 31 so a(13) = 3. In the same way, a(17) = 3.
From 22 we obtain 2 in two ways, so a(22) = 2.
a(101) = 2 because from the digits of 101 one can form the primes 11 (using digits 1 & 3) and 101 (using all digits). The prime 11 = 011 formed using all 3 digits does not count separately because it has a leading zero.
a(111) = 3 because one can form the prime 11 using digits 1 & 2, 1 & 3 or 2 & 3.
		

Crossrefs

Different from A039993 (counts only distinct primes). Cf. A072857, A076449.
Cf. A039999 (use all digits, count only distinct primes, allow leading zeros), A046810 (similar but don't allow leading zeros).
Cf. A134597 (maximum over all n-digit numbers), A076730 (maximum of A039993 for all n-digit numbers).
Cf. A239196 and A239197 for record indices and values.

Programs

  • Mathematica
    f[n_] := Length@ Select[ Union[ FromDigits@# & /@ Flatten[ Subsets@# & /@ Permutations@ IntegerDigits@ n, 1]], PrimeQ@# &]; Array[f, 105, 0] (* Robert G. Wilson v, Mar 12 2014 *)
  • PARI
    A075053(n,D=vecsort(digits(n)),S=0)=for(b=1,2^#D-1,forperm(vecextract(D,b),p,p[1]&&isprime(fromdigits(Vec(p)))&&S++));S \\ Second optional arg allows to give the digits if they are already known. - M. F. Hasler, Oct 14 2019, replacing earlier code from 2014.
    
  • Python
    from itertools import combinations
    from sympy.utilities.iterables import multiset_permutations
    from sympy import isprime
    def A075053(n): return sum(1 for l in range(1,len(str(n))+1) for a in combinations(str(n),r=l) for b in multiset_permutations(a) if b[0] !='0' and isprime(int(''.join(b)))) # Chai Wah Wu, Sep 13 2022

Formula

a(n) >= A039993(n) with equality iff n has no duplicate digit. - M. F. Hasler, Oct 14 2019
a(n) = Sum_{k in S(n)} A039999(k), if n has not more than one digit 0, where S(n) are the numbers whose nonzero digits are a subsequence of those of n, and which contain the digit 0 if n does, taken with multiplicity (for numbers using some but not all digits that are repeated in n). - M. F. Hasler, Oct 15 2019

Extensions

Corrected and extended by John W. Layman, Oct 15 2002
Examples & crossrefs edited by M. F. Hasler, Oct 14 2019

A262988 Number of distinct primes, including n if prime, obtained by cyclically shifting the digits of n.

Original entry on oeis.org

0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 2, 1, 0, 1, 1, 0, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 2, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0
Offset: 1

Views

Author

Felix Fröhlich, Oct 06 2015

Keywords

Comments

First differs from A039999 at n = 103.
Differs from A061264 iff n is a term of A004022.
a(n) = A055642(n) iff n is a term of A068652, except when n is also in A004022.

Examples

			a(1013) = 2, because of the four cyclic permutations of the digits of 1013 (1013, 131, 1310, 3101) two, namely 1013 and 131, are prime and those two primes are distinct.
		

Crossrefs

Programs

  • Mathematica
    f[n_] := Block[{len = IntegerLength@ n, s = {n}}, Do[AppendTo[s, FromDigits@ RotateRight@ IntegerDigits@ s[[k - 1]]], {k, 2, len}]; DeleteDuplicates@ Select[s, PrimeQ]]; Array[ Length@ f@ # &, {87}] (* Michael De Vlieger, Oct 07 2015 *)
  • PARI
    rot(n) = if(#Str(n)==1, v=vector(1), v=vector(#n-1)); for(i=2, #n, v[i-1]=n[i]); u=vector(#n); for(i=1, #n, u[i]=n[i]); v=concat(v, u[1]); v
    eva(n) = x=0; for(k=1, #n, x=x+(n[k]*10^(#n-k))); x
    a(n) = i=0; r=rot(digits(n)); while(r!=digits(n), if(ispseudoprime(eva(r)), i++); r=rot(r)); if(ispseudoprime(eva(r)), i++); i

A046891 Values of n where number of permutations of digits a(n) that are prime increases.

Original entry on oeis.org

1, 2, 13, 103, 107, 1007, 1013, 1049, 1079, 1237, 10013, 10039, 10079, 10139, 10237, 10279, 10379, 13789, 100127, 100139, 100235, 100237, 100279, 101237, 101239, 102347, 102367, 102379, 103579, 103789, 1001234, 1001237, 1001239, 1002347, 1002359, 1002367, 1002379
Offset: 1

Views

Author

Keywords

Crossrefs

Programs

  • Mathematica
    ap[n_] := Count[FromDigits /@ Permutations[IntegerDigits[n]], ?PrimeQ]; t = {1}; x = 0; Do[If[ap[i] > x, AppendTo[t, i]; x = ap[i]], {i, 105000}]; t (* _Jayanta Basu, Jun 29 2013 *)
  • Python
    from sympy import prime
    from gmpy2 import is_prime
    from sympy.utilities.iterables import multiset_permutations as mp
    from itertools import count, islice, combinations_with_replacement as mc
    def f(n): return sum(1 for p in mp(str(n)) if is_prime(t:=int("".join(p))))
    def bgen(d):
        for f in "123456789":
            yield from map(int, (f+"".join(m) for m in mc("0123456789", d-1)))
    def agen():
        record = -1
        for d in count(1):
            for k in bgen(d):
                v = f(k)
                if v > record:
                    record = v
                    yield k
    print(list(islice(agen(), 30))) # Michael S. Branicky, Feb 17 2024

Extensions

a(35) and beyond from Michael S. Branicky, Feb 17 2024

A046892 Number of permutations of digits of A046891(n) that are primes.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 13, 16, 18, 22, 31, 34, 37, 39, 40, 49, 52, 64, 80, 87, 93, 115, 121, 144, 149, 160, 172, 225, 233, 298, 299, 308, 384, 399, 408, 423, 475, 484, 569, 571, 738, 806, 835, 863, 934, 1247, 1413, 1525, 1739, 1775, 2282, 2303, 2325
Offset: 1

Views

Author

Keywords

Crossrefs

Programs

  • Mathematica
    a = {}; b = -1; Do[c = Count[ PrimeQ[ FromDigits /@ Permutations[IntegerDigits[n]]], True]; If[c > b, b = c; a = Append[a, c]], {n, 1, 10^8}]; a
  • Python
    from sympy import prime
    from gmpy2 import is_prime
    from sympy.utilities.iterables import multiset_permutations as mp
    from itertools import count, islice, combinations_with_replacement as mc
    def f(n): return sum(1 for p in mp(str(n)) if is_prime(t:=int("".join(p))))
    def bgen(d):
        for f in "123456789":
            yield from map(int, (f+"".join(m) for m in mc("0123456789", d-1)))
    def agen():
        record = -1
        for d in count(1):
            for k in bgen(d):
                v = f(k)
                if v > record:
                    record = v
                    yield v
    print(list(islice(agen(), 30))) # Michael S. Branicky, Feb 17 2024

A061264 Number of cyclic permutations of the digits of n which give primes.

Original entry on oeis.org

0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 2, 0, 2, 1, 0, 1, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 2, 1, 0, 1, 1, 0, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 2, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 2, 1, 0, 0, 2, 0, 2, 1, 0
Offset: 1

Views

Author

Amarnath Murthy, Apr 24 2001

Keywords

Examples

			a(157) = 2 as among the three cyclic permutations 157, 571, 715, two are primes.
		

Crossrefs

Cf. A039999.
Cf. A046810. - R. J. Mathar, Oct 02 2008

Programs

  • Maple
    A055642 := proc(n) max(1,ilog10(n)+1) ; end: A061264 := proc(n) local ncyc,s,dgs,a,L,i ; a := 0 ; dgs := convert(n,base,10) ; ncyc := n ; for s from 1 to A055642(n) do if isprime(ncyc) then a := a+1 ; fi; L := ListTools[Rotate](dgs,s) ; ncyc := add(op(i,L)*10^(i-1),i=1..nops(L)) ; od: RETURN(a) ; end: for n from 1 to 120 do printf("%d,",A061264(n)) ; od: # R. J. Mathar, Oct 02 2008

Extensions

More terms from R. J. Mathar, Oct 02 2008
Offset corrected, Joerg Arndt, Aug 05 2015

A086150 Number of permutations of decimal digits of n which yield nonprime numbers.

Original entry on oeis.org

1, 0, 0, 1, 0, 1, 0, 1, 1, 2, 0, 2, 0, 1, 2, 1, 0, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 1, 1, 0, 1, 1, 1, 1, 2, 0, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 0, 2, 0, 1, 2, 1, 1, 2, 0, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 0, 1, 1, 3, 1, 6, 3, 4, 6
Offset: 1

Views

Author

Labos Elemer, Aug 04 2003

Keywords

Comments

From Robert Israel, Aug 13 2017: (Start)
Leading zeros are allowed.
a(n) = 0 for n in A003459. (End)

Examples

			n=117, digit-permutations={117,171,711} are all composites, so a(117)=3.
		

Crossrefs

Programs

  • Maple
    f:= proc(L) option remember;
      nops(remove(isprime, map(t -> add(t[i]*10^(i-1),i=1..nops(t)), combinat:-permute(L))))
    end proc:
    seq(f(sort(convert(n,base,10))),n=1..200); # Robert Israel, Aug 13 2017
  • Mathematica
    nd[x_, y_] := 10*x+y tn[x_] := Fold[nd, 0, x] Table[Count[Table[PrimeQ[tn[Part[Permutations[ IntegerDigits[w]], j]]], {j, 1, Length[Permutations[ IntegerDigits[w]]]}], False], {w, 1, 128}]
    Table[Count[FromDigits/@Permutations[IntegerDigits[n]],?(!PrimeQ[#]&)],{n,110}] (* _Harvey P. Dale, Dec 24 2016 *)

Formula

a(n) + A039999(n) = A047726(n). - Robert Israel, Aug 13 2017

A046893 a(n) is the least number with exactly n permutations of digits that are primes.

Original entry on oeis.org

1, 2, 13, 103, 107, 1007, 1036, 1019, 1013, 1049, 1079, 1237, 10099, 10013, 10135, 10123, 10039, 10127, 10079, 10238, 10234, 10235, 10139, 10478, 12349, 12347, 10378, 12359, 14579, 10789, 100336, 10237, 12389, 23579, 10279, 100136, 12379, 10379, 100267, 13789
Offset: 0

Views

Author

Keywords

Comments

From Robert Israel, Feb 07 2023: (Start)
Permutations that have leading zeros are included, in contrast to A046890 where they are not.
If neither A046890(n) nor a(n) have the digit 0, then they are equal. (End)

Crossrefs

Cf. A039999, A046890. All terms are in A179239.

Programs

  • Maple
    g:= proc(d) local x,d1,y;
     [seq(seq(seq(x*10^d + y, y = [0,h(x,d1)]),d1=0..d-1),x=1..9)]
    end proc:
    g(0):= [$0..9]:
    h:= proc(x0, d) local y,z; option remember;
          seq(seq(y*10^d+z, z = [procname(y,d-1)]),y=x0..9)
    end proc:
    for x0 from 1 to 9 do h(x0,0):= $x0 .. 9 od:
    f:= proc(n) local t,L,d,P,i;
    t:= 0;
    L:= convert(n,base,10); d:= nops(L);
    for P in combinat:-permute(L) do
      if isprime(add(P[i]*10^(i-1),i=1..d)) then t:= t+1 fi
    od;
    t
    end proc:
    N:= 100: # for a(0)..a(N)
    V:= Array(0..N): count:= 0:
    for d from 0 while count < N+1 do
      for i in g(d) while count < N+1 do
      v:= f(i);
      if v <= N then
        if V[v] = 0 then V[v]:= i; count:= count+1; fi;
      fi
    od od:
    convert(V,list); # Robert Israel, Feb 07 2023
  • Mathematica
    a = Table[0, {40}]; Do[b = Count[ PrimeQ[ FromDigits /@ Permutations[ IntegerDigits[n]]], True]; If[b < 40 && a[[b + 1]] == 0, a[[b + 1]] = n; Print[b, " ", n]], {n, 1, 110000}]
  • Python
    from sympy import isprime
    from sympy.utilities.iterables import multiset_permutations as mp
    from itertools import count, islice, combinations_with_replacement as mc
    def nd(d): yield from ("".join((f,)+m) for f in "123456789" for m in mc("0123456789", d-1))
    def c(s): return sum(1 for p in mp(s) if p[0]!="0" and isprime(int("".join(p))))
    def agen(): # generator of sequence terms
        n, adict = 0, dict()
        for digs in count(1):
            for s in nd(digs):
                v = c(s)
                if v not in adict: adict[v] = int(s)
                while n in adict: yield adict[n]; n += 1
    print(list(islice(agen(), 40))) # Michael S. Branicky, Feb 08 2023
Showing 1-10 of 16 results. Next