Watson-Crick palindromes
05AB1E, 10 7 bytes
Code:
Â'š×‡Q
Explanation:
To check if a string is a palindrome, we just need to check the input with the input, with at
swapped and cg
swapped and then reverse it. So that is what we are going to do. We push the input and the input reversed using Â
(bifurcate). Now comes a tricky part. 'š×
is the compressed version for creating
. If we reverse it, you can see why it's in the code:
CreATinG
| || |
GniTAerC
This will be used to transliterate the reversed input. Transliteration is done with ‡
. After that, we just check if the input and the transliterated input are eQ
ual and print that value. So this is how the stack looks like for input actg
:
 # ["actg", "gtca"]
'š× # ["actg", "gtca", "creating"]
 # ["actg", "gtca", "creating", "gnitaerc"]
‡ # ["actg", "cagt"]
Q # [0]
Which can also be seen with the debug flag (Try it here).
Uses CP-1252 encoding. Try it online!.
Jelly, 9 bytes
O%8µ+U5ḍP
Try it online! or verify all test cases.
How it works
O%8µ+U5ḍP Main link. Argument: S (string)
O Compute the code points of all characters.
%8 Compute the residues of division by 8.
This maps 'ACGT' to [1, 3, 7, 4].
µ Begin a new, monadic link. Argument: A (array of residues)
+U Add A and A reversed.
5ḍ Test the sums for divisibility by 5.
Of the sums of all pairs of integers in [1, 3, 7, 4], only 1 + 4 = 5
and 3 + 7 = 10 are divisible by 5, thus identifying the proper pairings.
P Take the product of the resulting Booleans.
Python 2, 56 45 44 bytes
lambda s:s==s[::-1].translate("_T_GA__C"*32)