Jump to content

Piprimes: Difference between revisions

1,069 bytes added ,  2 years ago
Added Go
m (→‎{{header|Phix}}: added personal tag)
(Added Go)
Line 284:
{{out}}
<pre>0 1 2 2 3 3 4 4 4 4 5 5 6 6 6 6 7 7 8 8 8 8 9 9 9 9 9 9 10 10 11 11 11 11 11 11 12 12 12 12 13 13 14 14 14 14 15 15 15 15 15 15 16 16 16 16 16 16 17 17 18 18 18 18 18 18 19 19 19 19 20 20 21 21 21 21 21 21</pre>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<lang go>package main
 
import (
"fmt"
"rcu"
)
 
func main() {
primes := rcu.Primes(79) // go up to the 22nd
ix := 0
n := 1
count := 0
var pi []int
for {
if primes[ix] <= n {
count++
if count == 22 {
break
}
ix++
}
n++
pi = append(pi, count)
}
fmt.Println("pi(n), the number of primes <= n, where n >= 1 and pi(n) < 22:")
for i, n := range pi {
fmt.Printf("%2d ", n)
if (i+1)%10 == 0 {
fmt.Println()
}
}
fmt.Printf("\n\nHighest n for this range = %d.\n", len(pi))
}</lang>
 
{{out}}
<pre>
pi(n), the number of primes <= n, where n >= 1 and pi(n) < 22:
0 1 2 2 3 3 4 4 4 4
5 5 6 6 6 6 7 7 8 8
8 8 9 9 9 9 9 9 10 10
11 11 11 11 11 11 12 12 12 12
13 13 14 14 14 14 15 15 15 15
15 15 16 16 16 16 16 16 17 17
18 18 18 18 18 18 19 19 19 19
20 20 21 21 21 21 21 21
 
Highest n for this range = 78.
</pre>
 
=={{header|Julia}}==
9,476

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.