Smarandache-Wellin primes: Difference between revisions
→{{header|Wren}}: Merged the two previous solutions into one and also do extended stretch goal.
(Changed the stretch goal to better reflect what people are actually doing.) |
(→{{header|Wren}}: Merged the two previous solutions into one and also do extended stretch goal.) |
||
Line 446:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-gmp}}▼
Need to use GMP here to find the 8th S-W prime in a reasonable time (35.5 seconds on my Core i7 machine).▼
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./
import "./fmt"for Fmt▼
var primes = Int.primeSieve(
var sw = ""
var count = 0
var i = 0
var n = Mpz.new()▼
while (count < 3) {▼
sw = sw + primes[i].toString
if (
count = count + 1
}
i = i + 1
}
▲System.print("The first 3 Smarandache-Wellin primes are:")
var freqs = List.filled(10, 0)
count = 0
i = 0
while (count <
var p = primes[i].toString
for (d in p) {
Line 480 ⟶ 481:
}
var dsw = freqs.join("").trimStart("0")
▲System.print("\nThe first 3 Derived Smarandache-Wellin primes are:")
The first 3 Smarandache-Wellin primes are:▼
▲{{libheader|Wren-gmp}}
▲Need to use GMP here to find the 8th S-W prime in a reasonable time (35.5 seconds on my Core i7 machine).
▲import "./fmt"for Fmt
▲var n = Mpz.new()
if (n.probPrime(15) > 0) {
count = count + 1
▲ Fmt.print("$r: index $4d digits $4d last prime $5d", count, i+1, sw.count, primes[i])
}
i = i + 1
Line 526 ⟶ 491:
{{out}}
<pre>
The
6th: index 342 digits 1171 last prime 2297 -> 23571113171923293137...22732281228722932297
7th: index 435 digits 1543 last prime 3037 -> 23571113171923293137...30013011301930233037
8th: index 1429 digits 5719 last prime 11927 -> 23571113171923293137...11903119091192311927
1st: index 32 prime 4194123321127
2nd: index 72 prime 547233879626521
3rd: index 73 prime 547233979727521
4th: index 134 prime 13672766322929571043
5th: index 225 prime 3916856106393739943689
6th: index 303 prime 462696313560586013558131
7th: index 309 prime 532727113760586013758133
8th: index 363 prime 6430314317473636515467149
9th: index 462 prime 8734722823685889120488197
10th: index 490 prime 9035923128899919621189209
11th: index 495 prime 9036023329699969621389211
12th: index 522 prime 9337023533410210710923191219
13th: index 538 prime 94374237357103109113243102223
14th: index 624 prime 117416265406198131121272110263
15th: index 721 prime 141459282456260193137317129313
16th: index 738 prime 144466284461264224139325131317
17th: index 790 prime 156483290479273277162351153339
18th: index 852 prime 164518312512286294233375158359
19th: index 1087 prime 208614364610327343341589284471
20th: index 1188 prime 229667386663354357356628334581
</pre>
|