Solution Out Of The Box
=======================
Someone has requested my answer on Quora. The question is simple:
An abundant number is a number whose sum of divisors (not including
itself) is greater than the number itself; how many numbers below 30
are abundant?
The only way I know to solve such a question is to check each number
between 1 and 30. So, what solution out of the box can one find?
Many write scrips to answer the question.
So, my out-of-the-box solution is the following Tcl script:
is_abundant n {
set sum 0
for {set i 1} {$i<$n} {incr i} {
if $n%$i==0 {
incr sum $i
}
}
if $sum>$n {
return True
} else {
return False
}
}
for {set n 1} {$n<30} {incr n} {
if [is_abundant $n] {
puts $n
}
}