Primality by trial division: Difference between revisions

Content added Content deleted
m (→‎{{header|R}}: replaced buggy implementation (according to it 3 is not prime...). Mind the bounds in seq.)
Line 3,407: Line 3,407:


=={{header|R}}==
=={{header|R}}==
<lang rslang>is.prime <- function(n) n == 2 || n > 2 && n %% 2 == 1 && (n < 9 || all(n %% seq(3, floor(sqrt(n)), 2) > 0))
<lang rsplus>is.prime <- function(n) n == 2 || n > 2 && n %% 2 == 1 && (n < 9 || all(n %% seq(3, floor(sqrt(n)), 2) > 0))


which(sapply(1:100, is.prime))
which(sapply(1:100, is.prime))