Piprimes: Difference between revisions

m
(Initial FutureBasic task solution added)
m (→‎{{header|Wren}}: Minor tidy)
(2 intermediate revisions by one other user not shown)
Line 479:
<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
 
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
'~'1
NSUInteger n = 0, p = 1
printf @"Piprimes from 1 through %lu:\n", limit
 
printf @"Piprimes fromwhile 1( through %lu:\n", < limit )
printf @"%2lu \b", n
while ( n < limit )
if p mod 10 == 0 then print
printf @"%2lu \b", n
p++
if p mod 10 == 0 then print
if ( fn IsPrime(p) ) then n++
p++
wend
if ( fn IsPrime(p) ) then n++
wend
end fn
 
Line 520:
20 20 21 21 21 21 21 21
</pre>
 
 
 
=={{header|J}}==
Line 957 ⟶ 955:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var primes = Int.primeSieve(79) // go up to the 22nd
Line 978 ⟶ 974:
}
System.print("pi(n), the number of primes <= n, where n >= 1 and pi(n) < 22:")
for (chunk in Lst.chunks(pi, 10)) Fmt.printtprint("$2d", chunkpi, 10)
System.print("\nHighest n for this range = %(pi.count).")</syntaxhighlight>
 
9,476

edits