Piprimes: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(→{{header|Ruby}}: Add Ruby) |
m (→{{header|Wren}}: Minor tidy) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 474:
= 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|FutureBasic}}==
<syntaxhighlight futurebasic"j">
local fn IsPrime( n as NSUInteger ) as BOOL
BOOL isPrime = YES
NSUInteger i
if n < 2 then exit fn = NO
if n = 2 then exit fn = YES
if n mod 2 == 0 then exit fn = NO
for i = 3 to int(n^.5) step 2
if n mod i == 0 then exit fn = NO
next
end fn = isPrime
local fn Piprimes( limit as NSUInteger )
NSUInteger n = 0, p = 1
printf @"Piprimes from 1 through %lu:\n", limit
while ( n < limit )
printf @"%2lu \b", n
if p mod 10 == 0 then print
p++
if ( fn IsPrime(p) ) then n++
wend
end fn
fn Piprimes( 22 )
HandleEvents
</syntaxhighlight>
{{output}}}
<pre>
Piprimes from 1 through 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
</pre>
=={{header|J}}==
Line 909 ⟶ 955:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./
var primes = Int.primeSieve(79) // go up to the 22nd
Line 930 ⟶ 974:
}
System.print("pi(n), the number of primes <= n, where n >= 1 and pi(n) < 22:")
System.print("\nHighest n for this range = %(pi.count).")</syntaxhighlight>
|