Emirp primes: Difference between revisions
Content deleted Content added
Add Swift |
Add R solution |
||
Line 3,036: | Line 3,036: | ||
[948349]</pre> |
[948349]</pre> |
||
=={{header|R}}== |
|||
<lang rsplus> |
|||
library(gmp) |
|||
emirp <- function(start = 1, end = Inf, howmany = Inf, ignore = 0) { |
|||
count <- 0 |
|||
p <- start |
|||
while (count<howmany+ignore && p <= end) { |
|||
p <- nextprime(p) |
|||
p_reverse <- as.bigz(paste0(rev(unlist(strsplit(as.character(p), ""))), collapse = "")) |
|||
if (p != p_reverse && isprime(p_reverse) > 0) { |
|||
if (count >= ignore) cat(as.character(p)," ",sep="") |
|||
count <- count + 1 |
|||
} |
|||
} |
|||
cat("\n") |
|||
} |
|||
cat("First 20 emirps: ") |
|||
emirp(howmany = 20) |
|||
cat("Emirps between 7700 and 8000: ") |
|||
emirp(start = 7700, end = 8000) |
|||
cat("The 10000th emirp: ") |
|||
emirp(ignore = 9999, howmany = 1) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 20 emirps: 13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389 |
|||
Emirps between 7700 and 8000: 7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963 |
|||
The 10000th emirp: 948349 |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
This implementation seems to have exploded somewhat due to |
This implementation seems to have exploded somewhat due to |