OFFSET
1,2
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
EXAMPLE
a(115)=151 because 151 is the largest prime which can be made from digits {1,1,5}.
MAPLE
f:= proc(n) local L, N, d, i, j, S, s, p;
L:= convert(n, base, 10);
N:= nops(L);
for d from N to 1 by -1 do
S:= sort(combinat:-permute(L, d));
for i from nops(S) to 1 by -1 do
s:= S[i];
p:= add(s[j]*10^(d-j), j=1..d);
if isprime(p) then return p fi
od od;
0
end proc:
map(f, [$1..100]); # Robert Israel, Jan 10 2024
MATHEMATICA
a[n_]:=Max[0, Select[FromDigits/@Permutations[IntegerDigits[n], {1, IntegerLength[n]}], PrimeQ]]; Table[a[n], {n, 91}] (* James C. McMahon, Jan 08 2024 *)
CROSSREFS
KEYWORD
AUTHOR
Zak Seidov, Jan 29 2005
STATUS
approved