Prime numbers whose neighboring pairs are tetraprimes: Difference between revisions

→‎{{header|Wren}}: Rewritten to improve performance - more than 5 times quicker than before.
m (→‎{{header|Free Pascal}}: added runtimes for 1E7: 0.033s and 1E8: 0.458s ( 5600G @ 4.4 Ghz ))
(→‎{{header|Wren}}: Rewritten to improve performance - more than 5 times quicker than before.)
Line 1,266:
{{libheader|Wren-math}}
{{libheader|Wren-sort}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./sort" for Find
import "./seq" for Seq
import "./fmt" for Fmt
 
var primes = Int.primeSieve(1e7)
 
var isTetraPrime = Fn.new { |n|
var count = 0
var prevFact = 1
iffor (cond1p &&in cond2primes) {
if (cond3p * p &&<= cond4n) {
while (n % p == 0) {
if (count == 4 || p == prevFact) return false
count = count + 1
n = (n/p).floor
prevFact = p
}
} else {
break
}
}
if (n > 1) {
if (count == 4 || n == prevFact) return false
count = count + 1
}
return count == 4
}
 
var highest5 = primes[Find.nearest(primes, 1e5) - 1]
var highest6 = primes[Find.nearest(primes, 1e6) - 1]
Line 1,283 ⟶ 1,304:
var j = 1e5
for (p in primes) {
// process even numbers first as likely to have most factors
var pf1 = Int.primeFactors(p-2)
varif cond1 = pf1(isTetraPrime.count == 4call(p-1) && !SeqisTetraPrime.hasAdjDupcall(pf1p-2)) {
 
var pf2 = Int.primeFactors(p-1)
var cond2 = pf2.count == 4 && !Seq.hasAdjDup(pf2)
 
var pf3 = Int.primeFactors(p+1)
var cond3 = pf3.count == 4 && !Seq.hasAdjDup(pf3)
 
var pf4 = Int.primeFactors(p+2)
var cond4 = pf4.count == 4 && !Seq.hasAdjDup(pf4)
 
if (cond1 && cond2) {
tetras1.add(p)
if (pf1.contains(7p-1)%7 == 0 || pf2.contains(7p-2)%7 == 0) sevens1 = sevens1 + 1
}
 
if (cond3 && cond4) {
if (isTetraPrime.call(p+1) && isTetraPrime.call(p+2)) {
tetras2.add(p)
if (pf3.contains(7p+1)%7 == 0 || pf4.contains(7p+2)%7 == 0) sevens2 = sevens2 + 1
}
 
Line 1,387 ⟶ 1,398:
Maximum gap between those 10,551 primes : 10,284
</pre>
 
 
=={{header|XPL0}}==
9,476

edits