31
0
Introduction
This is one is pretty straightforward. We will be drawing a snake in ascii. This was inspired by that old snake game where you have to collect the fruit and you continuously grow.
Definition
Given a positive integer N that represents the snake's length, draw a snake so that it has a body of n plus a head and a tail.
Parts:
- head:
<, >, ^, v
- tail:
@
- vertical:
|
- horizonal:
-
All corners should be satisfied with a \
or /
respectively. Unless the head ends on a corner in which case the head <, >, ^, v
takes priority in the direction the snake is curled. i.e. for the length 1 example, it is turned counter clockwise and so the head is turned that way. For a clockwise solution it would be to the right >
.
The snake must start in the middle with its tail but it may go outwards in any direction you choose either clockwise or counter-clockwise. It must also wrap tightly around itself as it expands outwards in a circular fashion.
Example
/--\
|/\|
||@|
|\-/
\--->
Where the @
is the tail and starting position. As seen above the tail starts in the middle, goes up to the left in a counter-clockwise rotation outward.
Here the length is 19
plus a tail and a head.
As another example, here is length 1
:
<\
@
Winning
This is code-golf so the answer that is submitted with the smallest number of bytes wins, with time to be used as a tie breaker.
Have fun!
2It's not very clear that I'm not just allowed to draw a straight snake like
@---->
. You probably intend more strict conditions about the snake shape. Also make clear how much whitespace is or isn't allowed – Ton Hospel – 8 years ago1"The snake must start in the middle with it's tail but it may go outwards in any direction you choose and either clockwise or counter-clockwise" – jacksonecac – 8 years ago
1So I say
@
is the middle (possible add some spaces to make it so), declare "to the right" to be the direction and make just the head point down and declare that clockwise. Your terms may seem clear to you, but they are actually ambiguous. I realize you probably mean an as tightly as possible coiled snake, but you should make that clear – Ton Hospel – 8 years ago@TonHospel Else what kind of challenge is this? – Erik the Outgolfer – 8 years ago
http://codegolf.stackexchange.com/q/55819/21348 related – edc65 – 8 years ago
I haven't seen this :( – jacksonecac – 8 years ago
1Don't worry. That one is a lot harder due to the offsets in that challenge. – Martin Ender – 8 years ago
Your challenge could use a few more test cases though. Especially the minimum input would be good to know. – Martin Ender – 8 years ago
can you please give an output for n == 1 – Kishan Kumar – 8 years ago
I added a N = 1 example and clarified that the head takes priority over a corner – jacksonecac – 8 years ago
Related (but simpler) – DLosc – 8 years ago
Can we optionally take length including head and tail? The examples would be inputs
21
and3
respectively – Luis Mendo – 8 years agoNo, sorry :). There are already solutions posted. – jacksonecac – 8 years ago
2Nice first challenge! Welcome to the site! – Luis Mendo – 8 years ago
"Unless the head ends on a corner in which case the head <, >, ^, v takes priority in the direction the snake is curled" Should not the head be curved upwards in the example? It's in a corner. – Emilio M Bumachar – 8 years ago
@EmilioMBumachar are you referring to the N=1 example? The direction being clockwise vs counter-clockwise not N, S, E and W. – jacksonecac – 8 years ago
@LuisMendo thank you! I lurked for a long time :) – jacksonecac – 8 years ago
1why the hurry? you can wait how long you want to accept an answer (in fact you don't even need to accept one). If you accept an answer, it MAY discourage new answers – Rod – 8 years ago
@Rod Ok I'll keep it open awhile. I wasn't sure the protocol for these :) – jacksonecac – 8 years ago