Piprimes: Difference between revisions
Content added Content deleted
m (added whitespace.) |
(Added Wren) |
||
Line 122: | Line 122: | ||
Found 78 Piprimes. |
Found 78 Piprimes. |
||
done... |
done... |
||
</pre> |
|||
=={{header|Wren}}== |
|||
{{libheader|Wren-math}} |
|||
{{libheader|Wren-seq}} |
|||
{{libheader|Wren-fmt}} |
|||
<lang ecmascript>import "/math" for Int |
|||
import "/seq" for Lst |
|||
import "/fmt" for Fmt |
|||
var primes = Int.primeSieve(79) // go up to the 22nd |
|||
var ix = 0 |
|||
var n = 1 |
|||
var count = 0 |
|||
var pi = [] |
|||
while (true) { |
|||
if (primes[ix] <= n) { |
|||
count = count + 1 |
|||
if (count == 22) break |
|||
ix = ix + 1 |
|||
} |
|||
n = n + 1 |
|||
pi.add(count) |
|||
} |
|||
System.print("pi(n), the number of primes <= n, where n >= 1 and pi(n) < 22:") |
|||
for (chunk in Lst.chunks(pi, 10)) Fmt.print("$2d", chunk) |
|||
System.print("\nHighest n for this range = %(pi.count).")</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> |
</pre> |