Smarandache-Wellin primes: Difference between revisions
Content added Content deleted
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: | Line 198: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
===Basic=== |
|||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
⚫ | |||
⚫ | |||
<syntaxhighlight lang="go">package main |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
"fmt" |
"fmt" |
||
⚫ | |||
"rcu" |
"rcu" |
||
"strconv" |
"strconv" |
||
Line 210: | Line 212: | ||
func main() { |
func main() { |
||
primes := rcu.Primes( |
primes := rcu.Primes(12000) |
||
sw := "" |
sw := "" |
||
var swp []int |
|||
count := 0 |
count := 0 |
||
i := 0 |
i := 0 |
||
n := new(big.Int) |
|||
⚫ | |||
⚫ | |||
sw += strconv.Itoa(primes[i]) |
sw += strconv.Itoa(primes[i]) |
||
n |
n.SetString(sw, 10) |
||
if |
if n.ProbablyPrime(15) { |
||
⚫ | |||
count++ |
count++ |
||
⚫ | |||
⚫ | |||
⚫ | |||
sws = sws[0:20] + "..." + sws[le-20:le] |
|||
⚫ | |||
⚫ | |||
} |
} |
||
i++ |
i++ |
||
} |
} |
||
⚫ | |||
fmt.Printf("%v\n", swp) |
|||
⚫ | |||
freqs := make([]int, 10) |
freqs := make([]int, 10) |
||
var dswp []int |
|||
count = 0 |
count = 0 |
||
i = 0 |
i = 0 |
||
for count < |
for count < 20 { |
||
p := strconv.Itoa(primes[i]) |
p := strconv.Itoa(primes[i]) |
||
for _, d := range p { |
for _, d := range p { |
||
Line 242: | Line 248: | ||
} |
} |
||
dsw = strings.TrimLeft(dsw, "0") |
dsw = strings.TrimLeft(dsw, "0") |
||
n.SetString(dsw, 10) |
|||
if |
if n.ProbablyPrime(15) { |
||
dswp = append(dswp, dn) |
|||
count++ |
count++ |
||
fmt.Printf("%2dth: index %4d prime %v\n", count, i+1, n) |
|||
} |
} |
||
i++ |
i++ |
||
} |
} |
||
⚫ | |||
fmt.Printf("%v\n", dswp) |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
The |
The known Smarandache-Wellin primes are: |
||
⚫ | |||
[2 23 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 |
|||
⚫ | |||
⚫ | |||
The first |
The first 20 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 |
|||
⚫ | |||
6th: index 303 prime 462696313560586013558131 |
|||
⚫ | |||
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 |
|||
⚫ | |||
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:") |
|||
⚫ | |||
sw += strconv.Itoa(primes[i]) |
|||
n.SetString(sw, 10) |
|||
if n.ProbablyPrime(15) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
len(sw), primes[i]) |
|||
⚫ | |||
} |
|||
i++ |
|||
} |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
The 4th to the 8th Smarandache-Wellin primes are: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||