Skip to main content
3 of 3
Commonmark migration

Retina, 45 44 bytes

.*
$*
11(1+)
$1¶$&¶11$&
m`^(11+)\1+$

1<`1¶1

Returns 1 if the input is a twin prime, 0 otherwise

Try it online!

Explanation

.*              
$*

Convert to Unary

11(1+)          
$1¶$&¶11$&

Put n-2, n, and n+2 on their own lines

m`^(11+)\1+$   

(Trailing newline) Remove all composites greater than 1

1<`1¶1          

Check if there are two consecutive primes (or 1,3 because 3 is a twin prime)

PunPun1000
  • 983
  • 4
  • 7