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}}
{{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(
sw := ""
count := 0
i := 0
for count < 8 {▼
sw += strconv.Itoa(primes[i])
n
if
swp = append(swp, n)▼
count++
sws = sws[0:20] + "..." + sws[le-20:le]
}▼
}
i++
}
▲ fmt.Println("The first 3 Smarandache-Wellin primes are:")
freqs := make([]int, 10)
count = 0
i = 0
for count <
p := strconv.Itoa(primes[i])
for _, d := range p {
Line 242 ⟶ 248:
}
dsw = strings.TrimLeft(dsw, "0")
if
count++
fmt.Printf("%2dth: index %4d prime %v\n", count, i+1, n)
}
i++
}
▲ fmt.Println("\nThe first 3 Derived Smarandache-Wellin primes are:")
}</syntaxhighlight>
{{out}}
<pre>
The
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
1th: index 32 prime 4194123321127
2th: index 72 prime 547233879626521
3th: index 73 prime 547233979727521
4th: index 134 prime 13672766322929571043
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
8th: index 363 prime 6430314317473636515467149
9th: index 462 prime 8734722823685889120488197
10th: index 490 prime 9035923128899919621189209
11th: index 495 prime 9036023329699969621389211
▲ big "github.com/ncw/gmp"
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
▲ for count < 8 {
▲ count++
▲ if count > 3 {
▲ fmt.Printf("%dth: index %4d digits %4d last prime %5d\n", count, i+1,
▲ }
▲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>
|