Pierpont primes: Difference between revisions

Add Swift
(Add Swift)
Line 2,637:
1000th Pierpont prime of the 2nd kind: 1308088756227965581249669045506775407896673213729433892383353027814827286537163695213418982500477392209371001259166465228280492460735463423
</pre>
 
=={{header|Swift}}==
 
3-smooth version.
 
Using AttaSwift's BigInt library.
 
<lang swift>import BigInt
import Foundation
 
public func pierpoint(n: Int) -> (first: [BigInt], second: [BigInt]) {
var primes = (first: [BigInt](repeating: 0, count: n), second: [BigInt](repeating: 0, count: n))
 
primes.first[0] = 2
 
var count1 = 1, count2 = 0
var s = [BigInt(1)]
var i2 = 0, i3 = 0, k = 1
var n2 = BigInt(0), n3 = BigInt(0), t = BigInt(0)
 
while min(count1, count2) < n {
n2 = s[i2] * 2
n3 = s[i3] * 3
 
if n2 < n3 {
t = n2
i2 += 1
} else {
t = n3
i3 += 1
}
 
if t <= s[k - 1] {
continue
}
 
s.append(t)
k += 1
t += 1
 
if count1 < n && t.isPrime(rounds: 10) {
primes.first[count1] = t
count1 += 1
}
 
t -= 2
 
if count2 < n && t.isPrime(rounds: 10) {
primes.second[count2] = t
count2 += 1
}
}
 
return primes
}
 
 
let primes = pierpoint(n: 250)
 
print("First 50 Pierpoint primes of the first kind: \(Array(primes.first.prefix(50)))\n")
print("First 50 Pierpoint primes of the second kind: \(Array(primes.second.prefix(50)))")
print()
print("250th Pierpoint prime of the first kind: \(primes.first[249])")
print("250th Pierpoint prime of the second kind: \(primes.second[249])")</lang>
 
{{out}}
 
<pre>First 50 Pierpoint primes of the first kind: [2, 3, 5, 7, 13, 17, 19, 37, 73, 97, 109, 163, 193, 257, 433, 487, 577, 769, 1153, 1297, 1459, 2593, 2917, 3457, 3889, 10369, 12289, 17497, 18433, 39367, 52489, 65537, 139969, 147457, 209953, 331777, 472393, 629857, 746497, 786433, 839809, 995329, 1179649, 1492993, 1769473, 1990657, 2654209, 5038849, 5308417, 8503057]
 
First 50 Pierpoint primes of the second kind: [2, 3, 5, 7, 11, 17, 23, 31, 47, 53, 71, 107, 127, 191, 383, 431, 647, 863, 971, 1151, 2591, 4373, 6143, 6911, 8191, 8747, 13121, 15551, 23327, 27647, 62207, 73727, 131071, 139967, 165887, 294911, 314927, 442367, 472391, 497663, 524287, 786431, 995327, 1062881, 2519423, 10616831, 17915903, 18874367, 25509167, 30233087]
 
250th Pierpoint prime of the first kind: 62518864539857068333550694039553
250th Pierpoint prime of the second kind: 4111131172000956525894875083702271</pre>
 
=={{header|Wren}}==