Smarandache-Wellin primes: Difference between revisions

→‎{{header|Go}}: Changed in line with Wren solution of which it is a translation.
m ("4..20" was only from two-part implementations, task shd just say "first 20")
(→‎{{header|Go}}: Changed in line with Wren solution of which it is a translation.)
Line 198:
=={{header|Go}}==
{{trans|Wren}}
===Basic===
{{libheader|Go-rcu}}
{{libheader|GMP(Go wrapper)}}
We need to use the above GMP wrapper to match Wren's time of about 35.5 seconds as Go's native big.Int type is far slower.
<syntaxhighlight lang="go">package main
 
import (
"fmt"
big "github.com/ncw/gmp"
"rcu"
"strconv"
Line 210 ⟶ 212:
 
func main() {
primes := rcu.Primes(40012000)
sw := ""
var swp []int
count := 0
i := 0
forn count:= < 3 {new(big.Int)
fmt.Println("The first 3known Smarandache-Wellin primes are:")
for count < 8 {
sw += strconv.Itoa(primes[i])
n, _ := strconv.AtoiSetString(sw, 10)
if rcun.IsPrimeProbablyPrime(n15) {
swp = append(swp, n)
count++
count++sws := sw
swple := appendlen(swp, nsws)
if countle > 34 {
sws = sws[0:20] + "..." + sws[le-20:le]
}
fmt.Printf("%dth: index %4d digits %4d last prime %5d -> %s\n", count, i+1, len(sw), primes[i], sws)
}
i++
}
fmt.Println("The first 3 Smarandache-Wellin primes are:")
fmt.Printf("%v\n", swp)
 
fmt.Println("\nThe first 320 Derived Smarandache-Wellin primes are:")
freqs := make([]int, 10)
var dswp []int
count = 0
i = 0
for count < 320 {
p := strconv.Itoa(primes[i])
for _, d := range p {
Line 242 ⟶ 248:
}
dsw = strings.TrimLeft(dsw, "0")
dn, _ := strconvn.AtoiSetString(dsw, 10)
if rcun.IsPrimeProbablyPrime(dn15) {
dswp = append(dswp, dn)
count++
fmt.Printf("%2dth: index %4d prime %v\n", count, i+1, n)
}
i++
}
fmt.Println("\nThe first 3 Derived Smarandache-Wellin primes are:")
fmt.Printf("%v\n", dswp)
}</syntaxhighlight>
 
{{out}}
<pre>
The first 3known Smarandache-Wellin primes are:
4th1th: index 128 1 digits 355 1 last prime 719 2 -> 2
[2 23 2357]
5th2th: index 174 2 digits 499 2 last prime 1033 3 -> 23
6th3th: index 342 4 digits 1171 4 last prime 2297 7 -> 2357
4th: index 128 digits 355 last prime 719 -> 23571113171923293137...73677683691701709719
5th: index 174 digits 499 last prime 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:
1th: index 32 prime 4194123321127
[4194123321127 547233879626521 547233979727521]
2th: index 72 prime 547233879626521
</pre>
3th: index 73 prime 547233979727521
 
4th: index 134 prime 13672766322929571043
===Stretch===
5th: index 225 prime 3916856106393739943689
{{libheader|GMP(Go wrapper)}}
6th: index 303 prime 462696313560586013558131
We need to use the above GMP wrapper to match Wren's time of about 35.5 seconds as Go's native big.Int type is far slower.
7th: index 309 prime 532727113760586013758133
<syntaxhighlight lang="go">package main
8th: index 363 prime 6430314317473636515467149
 
9th: index 462 prime 8734722823685889120488197
import (
10th: index 490 prime 9035923128899919621189209
"fmt"
11th: index 495 prime 9036023329699969621389211
big "github.com/ncw/gmp"
12th: index 522 prime 9337023533410210710923191219
"rcu"
13th: index 538 prime 94374237357103109113243102223
"strconv"
14th: index 624 prime 117416265406198131121272110263
)
15th: index 721 prime 141459282456260193137317129313
 
16th: index 738 prime 144466284461264224139325131317
func main() {
17th: index 790 prime 156483290479273277162351153339
primes := rcu.Primes(12000)
18th: index 852 prime 164518312512286294233375158359
sw := ""
19th: index 1087 prime 208614364610327343341589284471
count := 0
20th: index 1188 prime 229667386663354357356628334581
i := 0
n := new(big.Int)
fmt.Println("The 4th to the 8th Smarandache-Wellin primes are:")
for count < 8 {
sw += strconv.Itoa(primes[i])
n.SetString(sw, 10)
if n.ProbablyPrime(15) {
count++
if count > 3 {
fmt.Printf("%dth: index %4d digits %4d last prime %5d\n", count, i+1,
len(sw), primes[i])
}
}
i++
}
}</syntaxhighlight>
 
{{out}}
<pre>
The 4th to the 8th Smarandache-Wellin primes are:
4th: index 128 digits 355 last prime 719
5th: index 174 digits 499 last prime 1033
6th: index 342 digits 1171 last prime 2297
7th: index 435 digits 1543 last prime 3037
8th: index 1429 digits 5719 last prime 11927
</pre>
 
9,476

edits