# Draw An ASCII Double Helix

Write a program that takes in an integer N via stdin or the command line.

If N is 0, the single letter O must be printed to stdout.

If N is positive, this horizontal ASCII art double helix, drawn N segments wide, must be printed.

If N is 1, the output is:

 /\
O  O
\/


If N is 2, the output is:

 /\ /\
O  /  O
\/ \/


If N is 3, the output is:

 /\ /\ /\
O  /  /  O
\/ \/ \/


If N is 4, the output is:

 /\ /\ /\ /\
O  /  /  /  O
\/ \/ \/ \/


The pattern continues in the exact same way for larger N. Note that forward slash (/) must be used in all places the helixes cross, except for the O ends.

If N is negative, this vertical ASCII art double helix, drawn -N segments tall, must be printed.

If N is -1, the output is:

 O
/ \
\ /
O


If N is -2, the output is:

 O
/ \
\ /
\
/ \
\ /
O


If N is -3, the output is:

 O
/ \
\ /
\
/ \
\ /
\
/ \
\ /
O


If N is -4, the output is:

 O
/ \
\ /
\
/ \
\ /
\
/ \
\ /
\
/ \
\ /
O


The pattern continues in the exact same way for smaller N. Note that backward slashes (\) must be used in all places the helixes cross, except for the O ends.

Details

• Instead of a program, you may write a function that takes N as an integer and prints the result normally or returns it as a string.
• The output for any N may optionally contain a trailing newline.
• Any line of output for any N may optionally contain 4 or fewer trailing spaces.
• There should never be any leading space that aren't part of the specified pattern.
• The shortest code in bytes wins.
• Brilliant Question! – Joshpbarron May 11 '15 at 9:11
• it seems to me that for n=0, it might be convenient to print <spc>O<spc>  or \nO\n. Is unnecesary leading whitespace allowed? – Level River St May 11 '15 at 13:31
• print "." Zoom in to see helix. *nodnod* – David Richerby May 11 '15 at 20:05
• @steveverrill That may have been helpful but there are so many answers now I don't want to change the rule. I've clarified that leading spaces not part of the pattern are not allowed. – Calvin's Hobbies May 11 '15 at 20:15

# C (gcc), 161 160 bytes

Now more compliant than ever! Thanks to @EriktheOutgolfer for making it so.

#define g(n)for(i=n;i--;)printf(
i;f(n){if(n<0){puts(" O");g(-n)"/ \\\n\\ /\n%2c\n",i?92:79);}else{g(n)" /\\");g(1)"\nO"+!n);g(n)i?"  /":"  O\n");g(n)" \\/");}}


Try it online!

• You can save a byte by making the Os uppercase. However, I think this answer is invalid (There should never be any leading space that aren't part of the specified pattern.) – Erik the Outgolfer Jan 21 '18 at 16:37
• @EriktheOutgolfer Ah, yes. Not sure why I added unnecessary spaces there. Also, thanks for pointing out the Os are capital, since I completely missed that. – gastropner Jan 21 '18 at 20:31

# SOGL V0.12, 37 bytes

 O¶/”▓:.θH{"⌠λ5⁸‘▓+};↕№+╬⁷.0>?I↔}.‽ O


Try it Here!

# Ruby, 118 138 bytes

->i{print i<0?" O ":" /\\"*i+"\n"*(1-0**i),i<0?("\n/ \\\n\\ /\n \\"*-i)[0..-3]:i==0&&"O"||"O "+" / "*(i-1)+" O\n",i<0?" O ":" \\/"*i+"\n"}


Basically a if-else statement on all the 3 parts of the helixes :)

Try it online!

Any tips to get it even smaller would be greatly appericated!

Edit: Silly me forgot to remove all the parantheses, and didnt see the requirement of "O" if 0