Factors of an integer: Difference between revisions
Content added Content deleted
(++ dc) |
No edit summary |
||
Line 2,976: | Line 2,976: | ||
96 => 1 2 3 4 6 8 12 16 24 32 48 96 |
96 => 1 2 3 4 6 8 12 16 24 32 48 96 |
||
</pre> |
</pre> |
||
=={{header|Lambdatalk}}== |
|||
<lang scheme> |
|||
{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} }}} |
|||
{lambda {:n} |
|||
{A.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> |
|||
=={{header|LFE}}== |
=={{header|LFE}}== |