Summarize primes: Difference between revisions

Added Go
(Added Wren)
(Added Go)
Line 36:
The sum of the first 158 primes is 66463 (which is prime).
The sum of the first 162 primes is 70241 (which is prime).
</pre>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<lang go>package main
 
import (
"fmt"
"rcu"
)
 
func main() {
primes := rcu.Primes(999)
sum, n, c := 0, 0, 0
fmt.Println("Summing the first n primes (<1,000) where the sum is itself prime:")
fmt.Println(" n cumulative sum")
for _, p := range primes {
n++
sum += p
if rcu.IsPrime(sum) {
c++
fmt.Printf("%3d %6s\n", n, rcu.Commatize(sum))
}
}
fmt.Println()
fmt.Println(c, "such prime sums found")
}</lang>
 
{{out}}
<pre>
Same as Wren example.
</pre>
 
9,492

edits