Sequence: smallest number with exactly n divisors: Difference between revisions

m
→‎{{header|REXX}}: added whitespace.
(Added Swift solution)
m (→‎{{header|REXX}}: added whitespace.)
Line 1,262:
say '──divisors── ──smallest number with N divisors──' /*display title for the numbers.*/
@.= /*the @ array is used for memoization*/
do i=1 for N; z= 1 + (i\==1) /*step through a number of divisors. */
do j=z by z /*now, search for a number that ≡ #divs*/
if @.j==. then iterate /*has this number already been found? */
d= #divs(j); if d\==i then iterate /*get # divisors; Is not equal? Skip.*/
say center(i, 12) right(j, 19) /*display the #divs and the smallest #.*/
@.j= . /*mark as having found #divs for this J*/
leave /*found a number, so now get the next I*/
end /*j*/
end /*i*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,318:
say '──divisors── ──smallest number with N divisors──' /*display title for the numbers.*/
@.=. /*the @ array is used for memoization*/
do i=1 for N; z= 1 + (i\==1) /*step through a number of divisors. */
do j=z by z /*now, search for a number that ≡ #divs*/
if @.j\==. then if @.j\==i then iterate /*if already been found, is it THE one?*/
d= #divs(j); if j<lim then @.j= d /*get # divisors; if not too high, save*/
if d\==i then iterate /*Is d ¬== i? Then skip this number*/
say center(i, 12) right(j, 19) /*display the #divs and the smallest #.*/
@.j= d /*mark as having found #divs for this J*/
leave /*found a number, so now get the next I*/
end /*j*/
end /*i*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/