Anti-primes: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: added REXX version 2 (that takes advantage of optimization by larger incrementation). |
Add Factor example |
||
Line 78: | Line 78: | ||
The first 20 anti-primes are: |
The first 20 anti-primes are: |
||
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 |
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 |
||
</pre> |
|||
=={{header|Factor}}== |
|||
<lang factor>USING: assocs formatting kernel locals make math |
|||
math.primes.factors sequences.extras ; |
|||
IN: rosetta-code.anti-primes |
|||
<PRIVATE |
|||
: count-divisors ( n -- m ) |
|||
dup 1 = [ group-factors values [ 1 + ] map-product ] unless ; |
|||
: (n-anti-primes) ( md n count -- ?md' n' ?count' ) |
|||
dup 0 > |
|||
[| max-div! n count! | |
|||
n count-divisors :> d |
|||
d max-div > [ d max-div! n , count 1 - count! ] when |
|||
max-div n dup 60 >= 20 1 ? + count (n-anti-primes) |
|||
] when ; |
|||
PRIVATE> |
|||
: n-anti-primes ( n -- seq ) |
|||
[ 0 1 ] dip [ (n-anti-primes) 3drop ] { } make ; |
|||
: anti-primes-demo ( -- ) |
|||
20 n-anti-primes "First 20 anti-primes:\n%[%d, %]\n" printf ; |
|||
MAIN: anti-primes-demo</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 20 anti-primes: |
|||
{ 1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040, 7560 } |
|||
</pre> |
</pre> |
||