Pandigital prime: Difference between revisions

→‎{{header|ALGOL 68}}: Alternative version based on the Delphi version
(→‎{{header|ALGOL 68}}: Alternative version based on the Delphi version)
Line 133:
max pandigital prime: 7652413
max pandigital0 prime: 76540231
</pre>
 
Alternative, faster version {{Trans|Delphi}}
The Algol 68 FOR loop allows the loop counter to vary by values other than 1/-1, which makes ignoring even numbers easier... : )
<syntaxhighlight lang="algol68">
FOR sp FROM 0 TO 1 DO
FOR x FROM IF sp = 1 THEN 7654321 ELSE 76543211 FI BY -2 TO 0 DO
IF x MOD 3 /= 0 THEN
STRING s = whole( x, 0 );
FOR ch FROM sp TO 7 DO IF NOT char in string( REPR ( ch + ABS "0" ), NIL, s ) THEN GOTO nxt FI OD;
INT i := 1;
WHILE i * i < x DO
IF x MOD ( i + 4 ) = 0 THEN GOTO nxt FI; i +:= 4;
IF x MOD ( i + 2 ) = 0 THEN GOTO nxt FI; i +:= 2
OD;
print( ( whole( sp, 0 ), "..7: ", whole( x, 0 ), newline ) ); GOTO done;
nxt: SKIP
FI
OD;
done: SKIP
OD
</syntaxhighlight>
 
{{out}}
<pre>
0..7: 76540231
1..7: 7652413
</pre>
 
3,021

edits