Aliquot sequence classifications: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: class -> classification (for better syntax colouring more than anything else))
m (→‎{{header|AppleScript}}: Minor improvements to handlers.)
Line 171: Line 171:


<lang applescript>on aliquotSum(n)
<lang applescript>on aliquotSum(n)
set sum to (n > 1) as integer
if (n < 2) then return 0
if (n > 1) then
set sum to 1
set sqrt to n ^ 0.5
set sqrt to n ^ 0.5
if (sqrt mod 1 is 0) then
repeat with i from (sqrt div 1) to 2 by -1
set sum to sum + sqrt as integer
if (n mod i is 0) then set sum to sum + i + n div i
end repeat
set sqrt to sqrt - 1
if (sqrt mod 1.0 is 0.0) then set sum to sum - sqrt div 1
end if
repeat with i from (sqrt div 1) to 2 by -1
if (n mod i is 0) then set sum to sum + i + n div i
end repeat
end if
return sum
return sum
Line 201: Line 197:
if (sequenceLength is 1) then
if (sequenceLength is 1) then
set classification to "perfect"
set classification to "perfect"
else if (sequence ends with 0) then
else if (n is 0) then
set classification to "terminating"
set classification to "terminating"
else if (n = k) then
else if (n = k) then