Factorial primes: Difference between revisions

Content added Content deleted
(Added Sidef)
(→‎{{header|ALGOL 68}}: Simplified also make it more DRY and less WET)
Line 31: Line 31:
=={{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.
<syntaxhighlight lang="algol68">BEGIN # find some factorial primes - primes that are f - 1 or f + 1 #
<syntaxhighlight lang="algol68">
BEGIN # find some factorial primes - primes that are f - 1 or f + 1 #
# for some factorial f #
# for some factorial f #


Line 43: Line 44:
prime
prime
FI;
FI;
# end of code based on the primality by trial divisio task #
# end of code based on the primality by trial division task #
PROC show factorial prime = ( INT fp number, INT n, CHAR fp op, LONG INT fp )VOID:
print( ( whole( fp number, -2 ), ":", whole( n, -4 )
, "! ", fp op, " 1 = ", whole( fp, 0 )
, newline
)
);
LONG INT f := 1;
LONG INT f := 1;
INT fp count := 0;
INT fp count := 0;
FOR n WHILE fp count < 10 DO
FOR n WHILE fp count < 10 DO
f *:= n;
f *:= n;
IF LONG INT fp = f - 1;
CHAR fp op := "-";
is prime( fp )
FOR offset FROM -1 BY 2 TO 1 DO
IF LONG INT fp = f + offset;
THEN
show factorial prime( fp count +:= 1, n, "-", fp )
is prime( fp )
FI;
THEN
IF LONG INT fp = f + 1;
print( ( whole( fp count +:= 1, -2 ), ":", whole( n, -4 )
is prime( fp )
, "! ", fp op, " 1 = ", whole( fp, 0 )
THEN
, newline
show factorial prime( fp count +:= 1, n, "+", fp )
)
FI
)
FI;
fp op := "+"
OD
OD
OD
END
END</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>