Skip to main content
Commonmark migration
Source Link

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

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)

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)

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)

removed non-greedy modifier (only normally used for performance reasons)
Source Link
PunPun1000
  • 983
  • 4
  • 7

Retina, 4545 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!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)

Retina, 45 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)

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)

Source Link
PunPun1000
  • 983
  • 4
  • 7

Retina, 45 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)