Anti-primes: Difference between revisions
Content added Content deleted
(Promote to full task status.) |
(→version 1: changed the format of the output from horizontal to vertical.) |
||
Line 353: | Line 353: | ||
if N=='' | N=="," then N=20 /*Not specified? Then use the default.*/ |
if N=='' | N=="," then N=20 /*Not specified? Then use the default.*/ |
||
maxD= 0 /*the maximum number of divisors so far*/ |
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 " " */ |
#= 0 /*the count of anti─primes found " " */ |
||
do once=1 for 1 |
|||
⚫ | |||
do |
do i=1 for 59 /*step through possible numbers by twos*/ |
||
if d<=maxD then iterate |
d= #divs(i); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/ |
||
#= # + 1; |
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/ |
||
say center(#, 7) right(i, 10) /*display the index and the anti─prime.*/ |
|||
⚫ | |||
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 /*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. */ |
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.*/ |
#divs: procedure; parse arg x 1 y /*X and Y: both set from 1st argument.*/ |
||
if x<3 then return x /*handle special |
if x<3 then return x /*handle special cases for one and two.*/ |
||
if x==4 then return 3 /* " " " " four. */ |
if x==4 then return 3 /* " " " " four. */ |
||
if x<6 then return 2 /* " " " " three or five*/ |
if x<6 then return 2 /* " " " " three or five*/ |
||
Line 383: | Line 390: | ||
{{out|output|text= when using the default input of: <tt> 20 </tt>}} |
{{out|output|text= when using the default input of: <tt> 20 </tt>}} |
||
<pre> |
<pre> |
||
─index─ ──anti─prime── |
|||
The first 20 anti─primes (highly─composite numbers) are: |
|||
1 1 |
|||
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> |
</pre> |
||