Factors of an integer: Difference between revisions

Content added Content deleted
No edit summary
Line 2,981: Line 2,981:
{def factors
{def factors
{def factors.r
{def factors.r
{lambda {:num :i :N :a}
{lambda {:num :i :N}
{if {> :i :N}
{if {> :i :N}
then :a
then
else {if {= {% :num :i} 0}
else {if {= {% :num :i} 0}
then {let { {:temp {A.addlast! :i :a}}}}
then :i
{if {not {= {/ :num :i} :i}}
{if {not {= {/ :num :i} :i}}
then {let { {:temp {A.addlast! {/ :num :i} :a}}}}
then {/ :num :i}
else}
else}
else} {factors.r :num {+ :i 1} :N :a} }}}
else}
{factors.r :num {+ :i 1} :N} }}}
{lambda {:n}
{lambda {:n}
{A.sort! < {factors.r :n 1 {sqrt :n} {A.new}}}}}
{S.sort < {factors.r :n 1 {sqrt :n}}}}}
-> factors
-> factors


{factors 45}
{factors 45}
-> [1,3,5,9,15,45]
-> 1 3 5 9 15 45
{factors 53}
{factors 53}
-> [1,53]
-> 1 53
{factors 64}
{factors 64}
-> [1,2,4,8,16,32,64]
-> 1 2 4 8 16 32 64

</lang>
</lang>