Factorial primes: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: More efficient basic version.) |
(→{{header|ALGOL 68}}: Tweak again) |
||
Line 30: | Line 30: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Basic task. Assumes LONG INT is at least 64 bits. |
Basic task. Assumes LONG INT is at least 64 bits. |
||
<lang algol68>BEGIN # find some factorial primes - primes that are f - 1 or f + 1 # |
<lang algol68>BEGIN # find some factorial primes - primes that are f - 1 or f + 1 # |
||
# |
# for some factorial f # |
||
# is prime PROC based on the one in the primality by trial division task # |
# is prime PROC based on the one in the primality by trial division task # |
||
Line 42: | Line 42: | ||
prime |
prime |
||
FI; |
FI; |
||
# end of code |
# end of code based on the primality by trial divisio task # |
||
PROC show factorial prime = ( INT fp number, INT n, CHAR fp op, LONG INT fp )VOID: |
PROC show factorial prime = ( INT fp number, INT n, CHAR fp op, LONG INT fp )VOID: |
||
Line 51: | Line 51: | ||
); |
); |
||
LONG INT f := 1; |
LONG INT f := 1; |
||
INT |
INT fp count := 0; |
||
FOR n WHILE fp count < 10 DO |
FOR n WHILE fp count < 10 DO |
||
f *:= n; |
f *:= n; |
||
LONG INT fp |
IF LONG INT fp = f - 1; |
||
is prime( fp ) |
|||
THEN |
THEN |
||
fp count +:= 1 |
show factorial prime( fp count +:= 1, n, "-", fp ) |
||
show factorial prime( fp count, n, "-", fp ) |
|||
FI; |
FI; |
||
fp |
IF LONG INT fp = f + 1; |
||
is prime( fp ) |
|||
THEN |
THEN |
||
fp count +:= 1 |
show factorial prime( fp count +:= 1, n, "+", fp ) |
||
show factorial prime( fp count, n, "+", fp ) |
|||
FI |
FI |
||
OD |
OD |