Perfect numbers: Difference between revisions
Content added Content deleted
m (→optimized using digital root: add/changed comments and whitespace.) |
(→traditional method: replaced with the appropriate REXX program.) |
||
Line 1,718:
:::* a ''corresponding factor'' is used when a factor is found
:::* testing is stopped if the sum of the factors exceeds '''X'''
<lang rexx>/*REXX program tests if a number (or a range of numbers) is/are perfect.
parse arg low high . /*obtain
if high=='' & low=='' then high=34000000 /*if no arguments,
if low=='' then low=1 /*if no LOW, then assume unity.
if high=='' then high=low /*if no HIGH, then assume LOW.
w=length(high) /*use W for formatting the output.
numeric digits max(9,w+2) /*ensure enough digits to handle number*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isPerfect: procedure; parse arg x
s=1 /*the first factor
▲ end /*j*/ /*(above) is marginally faster. */
'''output''' when using the default inputs:
6 is a perfect number.
|