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 |
{lambda {:num :i :N} |
||
{if {> :i :N} |
{if {> :i :N} |
||
then |
then |
||
else {if {= {% :num :i} 0} |
else {if {= {% :num :i} 0} |
||
then |
then :i |
||
{if {not {= {/ :num :i} :i}} |
{if {not {= {/ :num :i} :i}} |
||
then |
then {/ :num :i} |
||
else} |
else} |
||
else} |
else} |
||
{factors.r :num {+ :i 1} :N} }}} |
|||
{lambda {:n} |
{lambda {:n} |
||
{ |
{S.sort < {factors.r :n 1 {sqrt :n}}}}} |
||
-> factors |
-> factors |
||
{factors 45} |
{factors 45} |
||
-> |
-> 1 3 5 9 15 45 |
||
{factors 53} |
{factors 53} |
||
-> |
-> 1 53 |
||
{factors 64} |
{factors 64} |
||
-> |
-> 1 2 4 8 16 32 64 |
||
</lang> |
</lang> |
||