Anti-primes: Difference between revisions

1,296 bytes added ,  10 months ago
Added Miniscript
(→‎{{header|Lua}}: Added an alternative)
(Added Miniscript)
Line 2,793:
{{out}}
<pre>{1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720}</pre>
 
=={{header|MiniScript}}==
{{Trans|Lua|Using a table of divisor counts}}
<syntaxhighlight lang="miniscript">
// Find the first 20 antiprimes.
 
// returns a table of the first goal antiprimes
antiprimes = function(goal)
maxNumber = 0
ndc = [] // table of divisor counts - initially empty
list = [0] * goal; number = 1; mostFactors = 0
aCount = 0
while aCount < goal
if number > maxNumber then
// need a bigger table of divisor counts
maxNumber = maxNumber + 5000
ndc = [0] * ( maxNumber + 1 )
for i in range( 1, maxNumber )
ndc[ i ] = 1
end for
for i in range( 2, maxNumber )
for j in range( i, maxNumber, i )
ndc[ j ] = ndc[ j ] + 1
end for
end for
end if
factors = ndc[ number ]
if factors > mostFactors then
list[ aCount ] = number
mostFactors = factors
aCount = aCount + 1
end if
number = number + 1
end while
return list
end function
 
// display the antiprimes
print antiprimes( 20 ).join( " " )
</syntaxhighlight>
{{out}}
<pre>
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
 
=={{header|Modula-2}}==
3,043

edits