Jump to content

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}}==
===Basic===
{{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 "./fmtgmp" for FmtMpz
import "./fmt"for Fmt
 
var primes = Int.primeSieve(40012000)
var sw = ""
var swp = []
var count = 0
var i = 0
var n = Mpz.new()
while (count < 3) {
System.print("The first 3known Smarandache-Wellin primes are:")
while (count < 38) {
sw = sw + primes[i].toString
var n = Num.fromStringsetStr(sw)
if (Intn.isPrimeprobPrime(n15) > 0) {
swp.add(n)
count = count + 1
Fmt.print("$r: index $4d digits $4d last prime $5d -> $20a", count, i+1, sw.count, primes[i], n)
}
i = i + 1
}
System.print("The first 3 Smarandache-Wellin primes are:")
Fmt.print("$d", swp)
 
System.print("\nThe first 320 Derived Smarandache-Wellin primes are:")
var freqs = List.filled(10, 0)
var dswp = []
count = 0
i = 0
while (count < 320) {
var p = primes[i].toString
for (d in p) {
Line 480 ⟶ 481:
}
var dsw = freqs.join("").trimStart("0")
var dn = Numn.fromStringsetStr(dsw)
if (Int.isPrime(dn)) {
dswp.add(dn)
count = count + 1
}
i = i + 1
}
System.print("\nThe first 3 Derived Smarandache-Wellin primes are:")
Fmt.print("$d", dswp)</syntaxhighlight>
 
{{out}}
<pre>
The first 3 Smarandache-Wellin primes are:
2 23 2357
 
The first 3 Derived Smarandache-Wellin primes are:
4194123321127 547233879626521 547233979727521
</pre>
 
===Stretch===
{{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 "./gmp" for Mpz
import "./fmt"for Fmt
 
var primes = Int.primeSieve(12000)
var sw = ""
var count = 0
var i = 0
var n = Mpz.new()
System.print("The 4th to the 8th Smarandache-Wellin primes are:")
while (count < 8) {
sw = sw + primes[i].toString
n.setStr(sw)
if (n.probPrime(15) > 0) {
count = count + 1
if Fmt.print("$4r: index $4d prime $i", count, >i+1, 3n) {
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 4th to the 8thknown Smarandache-Wellin primes are:
4th1st: index 128 1 digits 355 1 last prime 719 2 -> 2
5th2nd: index 174 2 digits 499 2 last prime 1033 3 -> 23
6th3rd: index 342 4 digits 1171 4 last prime 2297 7 -> 2357
7th4th: index 435128 digits 1543 355 last prime 3037 719 -> 23571113171923293137...73677683691701709719
8th5th: index 1429 174 digits 5719 499 last prime 11927 1033 -> 23571113171923293137...10131019102110311033
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
 
The first 320 Derived Smarandache-Wellin primes are:
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>
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.