Another sequence, another challenge.*
Definition
A prime p
is in this sequence, let's call it A
, iff for every digit d
in p
's decimal expansion, you replace d
with d
copies of d
and the resulting integer is still prime; zeros are not permitted.
For example, 11
is trivially in this sequence (it's the first number, incidentally). Next in the sequence is 31
, because 3331
is also prime; then 53
because 55555333
is also prime, and so on.
Challenge
Given an input n
, return A(n)
, i.e. the n
th item in this sequence.
Examples
Here are the first 20 terms to get you started. This is A057628 on OEIS.
11, 31, 53, 131, 149, 223, 283, 311, 313, 331, 397, 463, 641, 691, 937, 941, 1439, 1511, 1741, 1871
This means A(0) = 11
, A(1) = 31
, etc., when using zero indexing.
Rules
- You can choose zero- or one-based indexing; please specify in your answer which.
- Instead of returning just the
n
th element, you can instead choose to return the firstn
terms. - You can assume that the input/output will not be larger than your language's native integer format; however, the repeated-digit prime may be larger than your language's native format, so that will need to be accounted for.
- For example,
1871
, the last number of the examples, has a corresponding prime of18888888877777771
, which is quite a bit larger than standard INT32. - Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Output can be to the console, returned from a function, displayed in an alert popup, etc.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
*To be fair, I had come up with the first few terms of the sequence just playing around with some numbers, and then went to OEIS to get the rest of the sequence.
169
itself isn't prime, it's13 * 13
. \$\endgroup\$