Find the Emirps!
05AB1E, 17 bytes
Uses CP-1252 encoding.
Input order is n, b
Output is in base-10.
µN²BÂD²öpŠÊNpPD–½
Try it online!
Explanation
# implicit input a,b
µ # loop until counter is a
N²B # convert current iteration number to base b
ÂD # create 2 reversed copies
²ö # convert one reversed copy to base 10
p # check for primality
ŠÊ # compare the normal and reversed number in base b for inequality
Np # check current iteration number for primality
P # product of all
D # duplicate
– # if 1, print current iteration number
½ # if 1, increase counter
Jelly, 16 bytes
bµU,ḅ⁹QÆPḄ=3
⁸ç#
TryItOnline!
How?
bµU,ḅ⁹QÆPḄ=3 - Link 1, in-sequence test: n, b
b - convert n to base b - a list
µ - monadic chain separation
U - reverse the list
, - pair with the list
⁹ - link's right argument, b
ḅ - convert each of the two lists from base b
Q - get unique values (if palindromic a list of only one item)
ÆP - test if prime(s) - 1 if prime, 0 if not
Ḅ - convert to binary
=3 - equal to 3? (i.e. [reverse is prime, forward is prime]=[1,1])
⁸ç# - Main link: b, N
# - count up from b *see note, and find the first N matches (n=b, n=b+1, ...) for:
ç - last link (1) as a dyad with left argument n and right argument
⁸ - left argument, b
* Note b
in base b
is [1,0]
, which when reversed is [0,1]
which is 1
, which is not prime; anything less than b
is one digit in base b
and hence palindromic.
Mathematica, 70 bytes
Cases[Prime@Range@437,p_/;(r=p~IntegerReverse~#2)!=p&&PrimeQ@r]~Take~#&
Works for 0 <= n <= 100
and 2 <= b <= 16
. From the list Prime@Range@437
of the first 437
primes, find the Cases
p
where the IntegerReverse
r
of p
in base #2
is not equal to p
and is also prime, then take the first #
such p
.
Here's a 95 byte solution that works for arbitrary n>=0
and b>=2
:
(For[i=1;a={},Length@a<#,If[(r=IntegerReverse[p=Prime@i,#2])!=p&&PrimeQ@r,a~AppendTo~p],i++];a)&