Primes whose first and last number is 3: Difference between revisions
Primes whose first and last number is 3 (view source)
Revision as of 10:31, 24 July 2021
, 2 years agoAdded Go
(Added Wren) |
(Added Go) |
||
Line 4:
<br><br>
=={{header|Go}}==
{{libheader|Go-rcu}}
<lang go>package main
import (
"fmt"
"rcu"
)
func main() {
var primes []int
candidates := []int{3, 33}
for i := 303; i <= 393; i += 10 {
candidates = append(candidates, i)
}
for i := 3003; i <= 3993; i += 10 {
candidates = append(candidates, i)
}
for _, cand := range candidates {
if rcu.IsPrime(cand) {
primes = append(primes, cand)
}
}
fmt.Println("Primes under 4,000 which begin and end in 3:")
for i, p := range primes {
fmt.Printf("%5s ", rcu.Commatize(p))
if (i+1)%11 == 0 {
fmt.Println()
}
}
fmt.Println("\nFound", len(primes), "Such primes.")
}</lang>
{{out}}
<pre>
Primes under 4,000 which begin and end in 3:
3 313 353 373 383 3,023 3,083 3,163 3,203 3,253 3,313
3,323 3,343 3,373 3,413 3,433 3,463 3,533 3,583 3,593 3,613 3,623
3,643 3,673 3,733 3,793 3,803 3,823 3,833 3,853 3,863 3,923 3,943
Found 33 Such primes.
</pre>
=={{header|Ring}}==
|