Anti-primes: Difference between revisions

→‎{{header|ALGOL 68}}: Use a dynamically allocated table of divisor counts to avoid a hard-coded limit
(Added Miniscript)
(→‎{{header|ALGOL 68}}: Use a dynamically allocated table of divisor counts to avoid a hard-coded limit)
Line 309:
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">BEGIN # find some anti-primes: numbers with more divisors than the #
BEGIN # find some # show theanti-primes: numbers with more divisors than their predecessors the #
# previous numbers #
REF[]INT maxndc number := 10HEAP[ 0001 : 0 ]INT; # table of divisor counts #
INT max divisors := 0;
INT a count := 0;
# construct a table of the divisor counts #
[ 1 : max number ]INT ndc; FOR in FROMWHILE 1a TOcount UPB< ndc20 DO ndc[ i ] := 1 OD;
FOR i FROM 2 TOIF n > UPB ndc DOTHEN
FOR j FROM i BY# ineed TOa UPBbigger ndctable DOof ndc[divisor jcounts ] +:= 1 OD #
ndc := HEAP[ 1 : UPB ndc + 5 000 ]INT;
OD;
FOR i FROM 1 TO UPB ndc DO ndc[ i ] := 1 OD;
# show the numbers with more divisors than their predecessors #
FOR i FROM 2 TO UPB ndc DO
INT a count := 0;
FOR j FROM i BY i TO UPB ndc WHILEDO andc[ countj <] 20+:= DO1 OD
INT divisor count = ndc[ i ];OD
OD FI;
IF divisor count > max divisors THEN
IF ndc[ n ] print(> (max "divisors ", whole( i, 0 ) ) );THEN
maxprint( divisors( :=" divisor", countwhole( n, 0 ) ) );
IF divisor count > max divisors THEN:= ndc[ n ];
a count +:= 1
FI
OD;
print( ( newline ) )
END
END</syntaxhighlight>
{{out}}
<pre>
3,032

edits