Recognizing Abundant, Deficient, and Perfect Numbers
Briefly

Recognizing Abundant, Deficient, and Perfect Numbers
"A quick bit of Googling turned up this explainer that basically boils it down to a simple principal. Given a number, find all the divisors of that number, excluding the number itself, and add them up. If the result is less than the original number, it is deficient. If the number is equal, it's perfect. Finally, if the sum is over the input, it's abundant."
"So for example, 6 is considered perfect because the divisors, 1+2+3, equal 6 when added together. 5, which only has a divisor of 1 (remember, you exclude the number itself) is deficient. 12 is abundant (1+2+3+4+6 == 16). You can read more, and see more variations, on the Encyclopedia.com article if you would like. Honestly, I see absolutely see use for this, but I thought - why not whip up a quick demo of this in BoxLang"
A classification method determines whether an integer is deficient, perfect, or abundant by summing its proper divisors (all divisors excluding the number itself) and comparing the sum to the original integer. Proper divisors can be found by iterating i from 1 up to ceiling(abs(n)/2) and checking n % i == 0, with a special-case for n == 1. A BoxLang implementation collects divisors into an array, returns them, then uses reduce to sum the array and compare the sum to the input: equal indicates perfect, greater-than indicates abundant, less-than indicates deficient. Examples include 6 (perfect), 5 (deficient), and 12 (abundant).
Read at Raymondcamden
Unable to calculate read time
[
|
]