Anti-primes: Difference between revisions

→‎version 1: changed the format of the output from horizontal to vertical.
(Promote to full task status.)
(→‎version 1: changed the format of the output from horizontal to vertical.)
Line 353:
if N=='' | N=="," then N=20 /*Not specified? Then use the default.*/
maxD= 0 /*the maximum number of divisors so far*/
say '─index─ ──anti─prime──' /*display a title for the numbers shown*/
#= 0 /*the count of anti─primes found " " */
do once=1 for 1
$= /*the list of anti─primes found " " */
do ji=1 untilfor #==N;59 d= #divs(j) /*obtain the number of divisors for K. /*step through possible numbers by twos*/
d= #divs(i); if d<=maxD then iterate /*get # divisors; /*Is D ≤ previous divtoo countsmall? Skip it. */
#= # + 1; maxD= d $= $ j /*found an anti─prime #,; add itset tonew listminD.*/
maxD= d say center(#, 7) right(i, 10) /*usedisplay thisthe asindex and the new high─water markanti─prime. */
$= if #>=N then leave once /*theif listwe ofhave enough anti─primes, found " "done. */
end /*i*/
 
do j=60 by 20 /*step through possible numbers by 20. */
d= #divs(j); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/
say center(#, 7) right(j, 10) /*display the index and the anti─prime.*/
if #>=N then leave once /*if we have enough anti─primes, done. */
end /*j*/
end /*once*/
say
say 'The first ' N " anti─primes (highly─composite numbers) are:"
say strip($)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
#divs: procedure; parse arg x 1 y /*X and Y: both set from 1st argument.*/
if x<3 then return x /*handle special casecases for one and two. */
if x==4 then return 3 /* " " " " four. */
if x<6 then return 2 /* " " " " three or five*/
Line 383 ⟶ 390:
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 20 </tt>}}
<pre>
─index─ ──anti─prime──
The first 20 anti─primes (highly─composite numbers) are:
1 2 4 61 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 75601
2 2
3 4
4 6
5 12
6 24
7 36
8 48
9 60
10 120
11 180
12 240
13 360
14 720
15 840
16 1260
17 1680
18 2520
19 5040
20 7560
</pre>