Factors of an integer: Difference between revisions

Line 270:
set realRoot to n ^ (1 / 2)
set intRoot to realRoot as integer
set blnPerfectSquare to intRoot = realRoot
-- Factors up to square root of n,
set lows to filter(mClosure(isFactor of mf, {n:n}), range(1, intRoot))
-- and quotients of these factors beyond the square root.
setreturn highslows to reverse of& map(mClosure(integerQuotient of mf, {n:n}), lows)¬
items (1 + (blnPerfectSquare as integer)) thru -1 of reverse of lows)
-- For perfect squares, no need to consider the head of the 'highs' list
if realRoot = intRoot then
lows & items 2 thru -1 of highs
else
lows & highs
end if
end integerFactors
 
 
on run
else
integerFactors(64120)
--> {1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120}
end run
 
Line 346 ⟶ 345:
property lambda : f
end script
end mClosure</lang>
</lang>
 
{{Out}}
9,655

edits