Anti-primes: Difference between revisions
Content deleted Content added
Line 1,230: | Line 1,230: | ||
{{out}} |
{{out}} |
||
<pre>[1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040, 7560]</pre> |
<pre>[1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040, 7560]</pre> |
||
=={{header|R}}== |
|||
Uses brute force. My first entry! |
|||
<lang R># Antiprimes |
|||
max_divisors <- 0 |
|||
findFactors <- function(x){ |
|||
myseq <- seq(x) |
|||
myseq[(x %% myseq) == 0] |
|||
} |
|||
antiprimes <- vector() |
|||
x <- 1 |
|||
n <- 1 |
|||
while(length(antiprimes) < 20){ |
|||
y <- findFactors(x) |
|||
if (length(y) > max_divisors){ |
|||
antiprimes <- c(antiprimes, x) |
|||
max_divisors <- length(y) |
|||
n <- n + 1 |
|||
} |
|||
x <- x + 1 |
|||
} |
|||
antiprimes</lang> |
|||
{{out}} |
|||
<pre> [1] 1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |