20
1
An emirp is a non-palindromic prime which, when reversed, is also prime.
The list of base 10 emirps can be found on OEIS. The first six are:
13, 17, 31, 37, 71, 73
However, due to the reversal rule, emirps are different in each base. For example, the first six binary emirps are:
Bin | 1011, 1101, 10111, 11101, 101001, 100101
Dec | (11 , 13 , 23 , 29 , 37 , 41 )
...and in hexadecimal, they are:
Hex | 17, 1F, 35, 3B, 3D, 53
Dec | (23, 31, 53, 59, 61, 83)
Fun Fact: there are no emirps in unary as every number is a palindrome.
The Challenge
Your task is to create a function (or full program) which takes two parameters, \$ n \$ and \$ b \$, and generates a list of the first \$ n \$ emirps in base \$ b \$.
Rules/Details:
- \$ n \$ and \$ b \$ are both positive integers larger than \$ 0 \$.
- You can assume \$ 2 ≤ b ≤ 16 \$: that is to say, the base will be between binary and hexidecimal.
- You should be able to compute for values of \$ n \$ up to \$ ~100 \$.
- The generated list can be in base \$ b \$, or your language's standard integer base, as long as you specify this in your answer.
- Builtin emirp checks are not permitted (builtin primality tests are fine)
- You cannot hard-code the emirps, or read from any external files.
- Standard loopholes are banned, as always.
- This is code-golf, so the shortest answer (in bytes) wins.
Test Cases
For each test case, I've included the list in base b
and its base 10 equivalents.
B = 2, N = 10
BIN: [1011, 1101, 10111, 11101, 100101, 101001, 101011, 101111, 110101, 111101]
DEC: [11, 13, 23, 29, 37, 41, 43, 47, 53, 61]
B = 3, N = 5
BASE3: [12, 21, 102, 201, 1011]
DEC: [5, 7, 11, 19, 31]
B = 12, N = 7
BASE12: [15, 51, 57, 5B, 75, B5, 107]
DEC: [17, 61, 67, 71, 89, 137, 151]
B = 16, N = 4
HEX: [17, 1F, 35, 3B]
DEC: [23, 31, 53, 59]
You can test your program further against my (ungolfed) Python example on repl.it
Congrats on winning! – FlipTack – 2016-11-16T17:29:22.190