Another sequence, another challenge.*
p is in this sequence, let's call it
A, iff for every digit
p's decimal expansion, you replace
d copies of
d and the resulting integer is still prime; zeros are not permitted.
11 is trivially in this sequence (it's the first number, incidentally). Next in the sequence is
3331 is also prime; then
55555333 is also prime, and so on.
Given an input
A(n), i.e. the
nth item in this sequence.
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
A(0) = 11,
A(1) = 31, etc., when using zero indexing.
- You can choose zero- or one-based indexing; please specify in your answer which.
- Instead of returning just the
nth element, you can instead choose to return the first
- 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 of
18888888877777771, 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.