Given a sequence of the bases Adenine, Cytosine, Guanine and Thymine (encoded as ACGT
), you're to produce an ASCII art representation of a corresponding double strand of DNA.
The strand will extend vertically. The left-hand strand is the one you are given as input. The right-hand strand will be its complement. For those not familiar with DNA, A
is paired with T
and C
is paired with G
. Furthermore, there is backbone structure on either side of the double strand which is identical for all bases. So if you were given the input TAGCAT
the large-scale structure of the ASCII art would be:
BTAB
BATB
BGCB
BCGB
BATB
BTAB
where B
represents the backbone. Now each of these letters stands for an entire molecule and you're to reproduce the actual molecular structure.
The Bases
Use the following templates1 for each of the bases (each one is displayed together with its complementary base and the two backbone molecules):
1Credits to Peter Taylor for helping out with the ASCII layout.
Adenine
O O
\\ /
P
/ \
--O O
/ |
< N NH2 ..... O * |
\ // \ / \\ / |
+--O // ---- ---- |
| \ | // \\ / \\ |
| >--N--< N ...... HN > ---+
| / \ / \ / / |
+--- N=== ---N--< |
| // \ |
| O O--+
| \
| >
| /
O O--
\ /
P
/ \\
O O
Cytosine
O O
\\ /
P
/ \
--O O NH2 ..... O N
/ / \\ / \\ |
< ---- ---- \\ ---+
\ // \\ / \\ | / |
+--O < N ...... HN >--N--< |
| \ \ / \ / \ |
| >--N--- ===N O--+
| / \\ / \
+--- O ..... H2N >
| /
O O--
\ /
P
/ \\
O O
Guanine
O O
\\ /
P
/ \
--O O
/ |
< N O ..... H2N |
\ // \ // \ |
+--O // ---- ---- |
| \ | // \ // \\ |
| >--N--< NH ...... N > ---+
| / \ / \ / / |
+--- N=== ---N--< |
| \ // \ |
| NH2 ..... O O--+
| \
| >
| /
O O--
\ /
P
/ \\
O O
Thymine
O O
\\ /
P
/ \
--O O * O ..... H2N N
/ \ // \ / \\ |
< ---- ---- \\ ---+
\ // \ // \\ | / |
+--O < NH ...... N >--N--< |
| \ \ / \ / \ |
| >--N--- ===N O--+
| / \\ \
+--- O >
| /
O O--
\ /
P
/ \\
O O
Constructing the Double Strand
These repeat vertically, such that there are no gaps in the backbone structure. This means that the bounding boxes of these four templates will overlap.
The bottom end of the left and top end of the right backbone will connect to the O
of an OH
.
The free O
at the top end of the left and bottom end of the right backbone will have a free bond going inwards, indicated by --
.
Example ATG
O O--
\\ /
P
/ \
--O O OH
/ |
< N NH2 ..... O * |
\ // \ / \\ / |
+--O // ---- ---- |
| \ | // \\ / \\ |
| >--N--< N ...... HN > ---+
| / \ / \ / / |
+--- N=== ---N--< |
| // \ |
| O O--+
| \
| >
| /
O O O O--
\\ / \ /
P P
/ \ / \\
--O O * O ..... H2N N O O
/ \ // \ / \\ |
< ---- ---- \\ ---+
\ // \ // \\ | / |
+--O < NH ...... N >--N--< |
| \ \ / \ / \ |
| >--N--- ===N O--+
| / \\ \
+--- O >
| /
O O O O--
\\ / \ /
P P
/ \ / \\
--O O O O
/ |
< N O ..... H2N |
\ // \ // \ |
+--O // ---- ---- |
| \ | // \ // \\ |
| >--N--< NH ...... N > ---+
| / \ / \ / / |
+--- N=== ---N--< |
| \ // \ |
| NH2 ..... O O--+
| \
| >
| /
OH O O--
\ /
P
/ \\
--O O
More Examples:
Here are the MD5 hashes of several more examples (without extraneous leading or trailing spaces):
ATG 2e4a906c44a96fe84134bf4346adf11c (this is the above example)
C e3648b8960967463784818c3eee57246
TTT 6028a90b05775905ef1a00e7a45463c5
TAGCAT 3b834d2b7b9adc4113ffabd52d354c41
GATTACA a19463f965c641d071e07da59d64a418
Let me know if you think any of these are wrong.
If you're unsure how to check your results' hashes reliably, try this online MD5 generator. Make sure that there is no trailing line break.
Further Notes
You may use leading or trailing spaces as you see fit. Of course, if you use leading spaces it has to be the same amount in each line.
If I have made any mistakes in copying the chemical structure, the above templates are still normative for the purposes of this challenge.
You may write a function or a program which takes the input string as a parameter, command-line argument via STDIN or expects it to be stored in a variable. Write the resulting ASCII art to STDOUT.
This is code golf, so the shortest answer (in bytes) wins.
TTT
because the string contained a trailing newline. \$\endgroup\$ATG
output and got different checksum. And different OS will get different checksums. You can try these withunix2dos, unix2mac...
. \$\endgroup\$Digest::MD5.hexdigest()
with Unix-style line endings. Also, none of them have a trailing new line. Paste it here - this online MD5 generator agrees with my hashes. \$\endgroup\$