Jump to content

Piprimes: Difference between revisions

432 bytes removed ,  2 years ago
→‎{{header|ALGOL 68}}: Use ALGOL 68-primes
m (→‎{{header|REXX}}: changed whitespace and comments, added a foot separator for the output.)
(→‎{{header|ALGOL 68}}: Use ALGOL 68-primes)
Line 13:
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # Show some values of pi(n) - the number of priems <= n #
# reurns a sieve of primes up to n #
PROC prime sieve = ( INT n )[]BOOL:
BEGIN
[ 1 : n ]BOOL p;
p[ 1 ] := FALSE; p[ 2 ] := TRUE;
FOR i FROM 3 BY 2 TO n DO p[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO n DO p[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( n ) DO
IF p[ i ] THEN FOR s FROM i * i BY i + i TO n DO p[ s ] := FALSE OD FI
OD;
p
END # prime sieve # ;
# show pi(n) for n up to 21 #
INT max numberprime = 100; # guess of how large the primes we need are #
INT max pi = 21;
PR read "primes.incl.a68" PR
[]BOOL prime = prime sieve(PRIMESIEVE max number )prime;
INT pi := 0;
FOR i TO maxUPB numberprime
WHILE IF prime[ i ] THEN pi +:= 1 FI;
pi <= max pi
Line 50 ⟶ 40:
20 20 21 21 21 21 21 21
</pre>
 
=={{header|Arturo}}==
 
3,038

edits

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