A twin prime is a prime number that is either 2 less or 2 more than another prime number —for example, the twin prime pair (41, 43). In other words, a twin prime is a prime that has a prime gap of two. Sometimes the term twin prime is used for a pair of twin primes; an alternative name for this is prime twin or prime pair. Wikipedia
Although I didn't like much the depressing novel, and since I have fallen into PPCG lately, that raised a question in my mind...
Given a positive integer number N > 4, find the lonely prime numbers (AKA isolated prime numbers) between the closest couples of twin primes.
Please note that in this case with the term lonely prime numbers, I mean all the prime numbers that are not twin primes and between couples of twin primes. That's why N > 4 because the first two couples of prime numbers are (3, 5) and (5, 7).
- N = 90.
- Find the first two couples of twin primes < N and > N. They are: (71, 73) and (101, 103).
- Find the lonely primes in the range > 73 and < 101.
- They are: 79, 83, 89, 97.
- If N is in between two twin prime numbers, find the closest couples of twin primes > N+1 and < N-1. Example: N=72, find the closest couples of twin primes > 73 and < 71 then exclude from the list 71 and 73 because they are not lonely primes. So for N = 72 the expected result is: 67,
71, 73, 79, 83, 89, 97
- If N belongs to a couple of twin primes, for example N = 73, the closest couples of twin primes are (71, 73) and (101, 103). If N = 71, the closest couples of twin primes are (59, 61) and (71, 73).
N = 70 > Lonely primes are: 67 N = 71 > Lonely primes are: 67 N = 72 > Lonely primes are: 67, 79, 83, 89, 97 (not the twins 71 and 73) N = 73 > Lonely primes are: 79, 83, 89, 97 N = 90 > Lonely primes are: 79, 83, 89, 97 N = 201 > Lonely primes are: 211, 223 N = 499 > Lonely primes are: 467, 479, 487, 491, 499, 503, 509
- Write a full program or function that will take the number N from standard input.
- Output the list of lonely primes in a readable format as csv, list, array, etc.
- Shortest code wins.
- Please include (when possible) a testable online fiddle.