24
The Sequence
Everyone knows the only even prime number is 2. Ho-hum. But, there are certain even numbers n where, when concatenated with n-1, they become a prime number.
For starters, 1 isn't in the list, because 10 isn't prime. Similarly with 2 (21), and 3 (32). However, 4 works because 43 is prime, so it's the first number in the sequence a(1) = 4. The next number that works (neither 6 (65) nor 8 (87) work) is 10, because 109 is prime, so a(2) = 10. Then we skip a bunch more until 22, because 2221 is prime, so a(3) = 22. And so on.
Obviously all terms in this sequence are even, because any odd number n when concatenated with n-1 becomes even (like 3 turns into 32), which will never be prime.
This is sequence A054211 on OEIS.
The Challenge
Given an input number n that fits somewhere into this sequence (i.e., n concatenated with n-1 is prime), output its position in this sequence. You can choose either 0- or 1-indexed, but please state which in your submission.
Rules
- The input and output can be assumed to fit in your language's native integer type.
- The input and output can be given in any convenient format.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Examples
The below examples are 1-indexed.
n = 4
1
n = 100
11
n = 420
51
1Why do you have to do it in reverse? cQuents doesn't have that mode :( – Stephen – 2017-08-03T15:12:56.247
4@StepHen Just for a change of pace; something different than the usual. – AdmBorkBork – 2017-08-03T15:26:25.253
9I feel this would be much better as a decision problem. – Post Rock Garf Hunter – 2017-08-03T16:41:41.460
4Not only is 2 the only prime number divisible by 2, 3 is also the only prime number divisible by 3, and 5 is the only prime number divisible by 5. In general, a prime number
nis always the only prime number divisible byn. It's not special - that's just how prime numbers work. – Esolanging Fruit – 2017-08-04T03:46:09.347