Factors of an integer: Difference between revisions

No edit summary
Line 2,981:
{def factors
{def factors.r
{lambda {:num :i :N :a}
{if {> :i :N}
then :a
else {if {= {% :num :i} 0}
then {let { {:temp {A.addlast! :i :a}}}}
{if {not {= {/ :num :i} :i}}
then {let { {:temp {A.addlast! {/ :num :i} :a}}}}
else}
else} {factors.r :num {+ :i 1} :N :a} }}}
{factors.r :num {+ :i 1} :N} }}}
{lambda {:n}
{AS.sort! < {factors.r :n 1 {sqrt :n} {A.new}}}}}
-> factors
 
{factors 45}
-> [1, 3, 5, 9, 15, 45]
{factors 53}
-> [1, 53]
{factors 64}
-> [1, 2, 4, 8, 16, 32, 64]
 
</lang>