Pierpont primes: Difference between revisions

m
(→‎{{header|Perl 6}}: Rearrange a bit, move stuff out of the hot loop, cut runtime by ~40%)
Line 167:
 
=={{header|Julia}}==
The generator method is very fast but does not guarantee the primes are generated in order. Therefore we generate threetwo times the primes needed and then sort and return the bottomlower thirdhalf.
<lang julia>using Primes
 
function pierponts(N, firstkind = true)
count, ret, incdec = 0, BigInt[], firstkind ? 1 : -1
for k2 in 0:100010000, k3 in 0:k2, switch in false:true
i, j = switch ? (k3, k2) : (k2, k3)
n = BigInt(2)^i * BigInt(3)^j + incdec
if !isprime(n in ret) && isprime!(n in ret)
push!(ret, n)
if length(ret) == N * 32
return sort(ret)[1:N]
end
end
end
throw("Failed to find $(N * 2) primes")
end
 
println("The first 50 Pierpont primes (first kind) are: ", pierponts(50))
Line 193 ⟶ 192:
 
println("\nThe 250th Pierpont prime (second kind) is: ", pierponts(250, false)[250])
 
println("\nThe 1000th Pierpont prime (first kind) is: ", pierponts(1000)[1000])
 
println("\nThe 1000th Pierpont prime (second kind) is: ", pierponts(1000, false)[1000])
 
println("\nThe 2000th Pierpont prime (first kind) is: ", pierponts(2000)[2000])
 
println("\nThe 2000th Pierpont prime (second kind) is: ", pierponts(2000, false)[2000])
</lang>{{out}}
<pre>
Line 202 ⟶ 209:
 
The 250th Pierpont prime (second kind) is: 4111131172000956525894875083702271
 
The 1000th Pierpont prime (first kind) is: 69269314716439690250482558089997110961545818230232043107188537422260188701607997086273960899938499201024414931399264696270849
 
The 1000th Pierpont prime (second kind) is: 1308088756227965581249669045506775407896673213729433892383353027814827286537163695213418982500477392209371001259166465228280492460735463423
 
The 2000th Pierpont prime (first kind) is: 23647056334818750458979408107288138983957799805326855934519920502493109431728722178351835778368596067773810122477389192659352731519830867553659739507195398662712180250483714053474639899675114018023738461139103130959712720686117399642823861502738433
 
The 2000th Pierpont prime (second kind) is: 1702224134662426018061116932011222570937093650174807121918750428723338890211147039320296240754205680537318845776107057915956535566573559841027244444877454493022783449689509569107393738917120492483994302725479684822283929715327187974256253064796234576415398735760543848603844607
</pre>
 
4,108

edits