16 lines
429 B
Plaintext
16 lines
429 B
Plaintext
-- in some movie script
|
|
----------------------------------------
|
|
-- Prints all perfect numbers up to n
|
|
-- @param {integer|float} n
|
|
----------------------------------------
|
|
on findPerfects (n)
|
|
repeat with i = 2 to n
|
|
sum = frac(1, i)
|
|
cnt = sqrt(i)
|
|
repeat with fac = 2 to cnt
|
|
if i mod fac = 0 then sum = fAdd(sum, frac(1, fac), frac(fac, i))
|
|
end repeat
|
|
if sum.denom = sum.num then put i
|
|
end repeat
|
|
end
|