55
4
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.
9Brilliant Question! – Joshpbarron – 2015-05-11T09:11:06.073
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 – 2015-05-11T13:31:11.4801
print "."
Zoom in to see helix. *nodnod* – David Richerby – 2015-05-11T20:05:20.150@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 – 2015-05-11T20:15:32.980