A 11-digit number is such that it contains each of the digits from 1 to 9
at least once.
What is the percentage of prime numbers in such an occurrence?
The program does one million trials. Each trial starts with a random permutation of the digits 1 through 9. Then digits randomly chosen from 0 through 9 are placed randomly relative to the existing digits until an 11-digit number is formed (it will not place a zero before the first digit, so it might need more than two tries to achieve 11 digits).
primeCt=0;
for trial=1:1000000
p=randperm(9);
while length(p)<11
d= randi(10)-1 ;
psn=randi(length(p)+1);
if d>0 || psn>1
p=[p(1:psn-1) d p(psn:end)];
end
end
p=str2double(erase(num2str(p),' '));
if isprime(p)
primeCt=primeCt+1;
end
end
primeCt/trial
It found 43878 primes in the million trials for a probability of 0.043878, or 4.4%.
|
Posted by Charlie
on 2024-07-13 09:20:13 |