I'm trying to make a list of numbers that are twin primes. I wrote a function to check if a number is a twin prime or not.
Attributes[twinPrimeQ] = {Listable};
twinPrimeQ[n_] :=
PrimeQ[n] &&
n > 2 && (NextPrime[n] - n == 2 || n - NextPrime[n, -1] == 2)
How can I apply that to a list of integers, to pick out the twin primes, which will hopefully be those at https://oeis.org/A001097 ?
I thought something like this would work
In[19]:= Table[n, {n, 0, 20}] /; twinPrimeQ[n]
Out[19]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20} /; twinPrimeQ[n]
but it obviously does not work as I intended.