Jump to content

Minimum primes: Difference between revisions

→‎{{header|ALGOL 68}}: Make the sieve sie more appropriate for the elements
(Realize in F#)
(→‎{{header|ALGOL 68}}: Make the sieve sie more appropriate for the elements)
Line 18:
{{Trans|Wren}}
Can handle the possibility of the maximum elements being negative, 0, 1 or 2.
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # show the minimum prime >= the maximum elements of three lists #
PR read "primes.incl.a68" PR
[]BOOL prime = PRIMESIEVE 1000; # should be enough primes for this task... #
[]INT numbers1 = ( 5, 45, 23, 21, 67 );
[]INT numbers2 = ( 43, 22, 78, 46, 38 );
[]INT numbers3 = ( 9, 98, 12, 54, 53 );
[ 1 : UPB numbers1 ]INT prime list;
INT max element := numbers1[ 1 ];
FOR i TO UPB numbers1 DO
INT m := numbers1[ i ];
IF numbers2[ i ] > m THEN m := numbers2[ i ] FI;
IF numbers3[ i ] > m THEN m := numbers3[ i ] FI;
IF m > max element THEN max element := m FI;
prime list[ i ] := m
OD;
# construct a sieve of primes big enough for the maximum element #
[]BOOL prime = PRIMESIEVE 1000;( #max shouldelement be* enough2 primes for this task... #);
# replace the elements of prime list wih the smallest prime >= the element #
FOR i TO UPB prime list DO
INT m := prime list[ i ];
# find the next prime >= m #
IF m <= 2 THEN m := 2
3,043

edits

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