Anonymous user
Count in factors: Difference between revisions
→{{header|REXX}}: used "internal" type subroutine name, removed superfluous STRIP invocation, changed statement indentation, added whitespace, change/added comments. -- ~~~~
m (→{{header|REXX}}: added highlights and whitespace in the REXX section header. -- ~~~~) |
(→{{header|REXX}}: used "internal" type subroutine name, removed superfluous STRIP invocation, changed statement indentation, added whitespace, change/added comments. -- ~~~~) |
||
Line 1,478:
<br><br>Also, as per the task's requirements, the prime factors of '''1''' (unity) will be listed as '''1''',
<br>even though, strictly speaking, it should be '''null'''.
<lang rexx>/*REXX program
numeric digits
parse arg low high . /*get the argument(s)
if high=='' then high=low
w=length(high) /*get max width for pretty tell. */
blanks=1 /*allow spaces around the
do n=low to high /*process single number | a range*/
say right(n,w) '=' space(factr(n),blanks) /*display N & factors*/
Line 1,489:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────FACTR subroutine────────────────────*/
factr: procedure; parse arg x 1 z /*defines X and Z from the arg.
if x <1 then return '' /*
if x==1 then return 1 /*handle special case for unity.
Xtimes= 'x' /*character used for "times" (x).*/
list= /*nullify the list (to empty). */
do j=2 to 5; if j\==4 then call .buildF; end
j=5 /*start were we left off (five).*/
▲j=5 /*start were we left off (five).*/
do y=0 by 2; j=j+2+y//4 /*insure it's not divisible by 3.*/
if right(j,1)==5 then iterate /*fast check for divisible by 5.*/
if j>z then leave /*number reduced to a small 'un? */
if j*j>x then leave /*are we higher than the √ of X ?*/
call .buildF
end /*y*/
if z==1 then z= /*if residual is = 1, nullify it.*/
return
/*──────────────────────────────────.BUILDF subroutine──────────────────*/
.buildF: do while z//j==0
list=list Xtimes j
z=z%j
end /*while*/
return</lang>
'''output''' when using the input of: <tt> 1 30 </tt>
|