Anti-primes: Difference between revisions
Content added Content deleted
m (→{{header|PL/0}}: {{trans|Tiny BASIC}} added.) |
(adding lambdatalk) |
||
Line 2,260: | Line 2,260: | ||
</pre> |
</pre> |
||
=={{header|Lambdatalk}}== |
|||
<syntaxhighlight lang="scheme"> |
|||
{def factors |
|||
{def factors.filter |
|||
{lambda {:n :a :i} |
|||
{if {= {% :n :i} 0} |
|||
then {A.addlast! :i :a} |
|||
else}}} |
|||
{lambda {:n} |
|||
{S.last |
|||
{S.map {factors.filter :n {A.new}} |
|||
{S.serie 1 :n}}}}} |
|||
-> factors |
|||
{def antiprimes |
|||
{def antiprimes.filter |
|||
{lambda {:ap :max :i} |
|||
{let { {:ap :ap} {:max :max} {:i :i} |
|||
{:len {A.length {factors :i}}} |
|||
} {if {> :len {A.get 0 :max}} |
|||
then {A.addlast! :i :ap} |
|||
{A.set! 0 :len :max} |
|||
else} }}} |
|||
{lambda {:n} |
|||
{S.first |
|||
{S.map {antiprimes.filter {A.new 1} {A.new 1}} |
|||
{S.serie 1 :n}}}}} |
|||
-> antiprimes |
|||
{antiprimes 8000} // 8000 choosen manually to reach 20 antiprimes |
|||
-> [1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560] |
|||
// in 105400ms on my iPad |
|||
</syntaxhighlight> |
|||
=={{header|langur}}== |
=={{header|langur}}== |