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 – 2016-10-04T11:57:58.2731"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 – 2016-10-04T11:59:33.720
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 – 2016-10-04T12:10:02.523@TonHospel Else what kind of challenge is this? – Erik the Outgolfer – 2016-10-04T13:08:58.643
http://codegolf.stackexchange.com/q/55819/21348 related – edc65 – 2016-10-04T13:54:22.073
I haven't seen this :( – jacksonecac – 2016-10-04T13:55:38.083
1Don't worry. That one is a lot harder due to the offsets in that challenge. – Martin Ender – 2016-10-04T14:07:32.280
Your challenge could use a few more test cases though. Especially the minimum input would be good to know. – Martin Ender – 2016-10-04T14:07:55.643
can you please give an output for n == 1 – Kishan Kumar – 2016-10-04T14:14:33.803
I added a N = 1 example and clarified that the head takes priority over a corner – jacksonecac – 2016-10-04T14:39:51.110
Related (but simpler) – DLosc – 2016-10-04T16:51:39.373
Can we optionally take length including head and tail? The examples would be inputs
21
and3
respectively – Luis Mendo – 2016-10-04T17:36:46.947No, sorry :). There are already solutions posted. – jacksonecac – 2016-10-04T17:39:14.340
2Nice first challenge! Welcome to the site! – Luis Mendo – 2016-10-04T18:14:40.210
"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 – 2016-10-04T18:37:07.867
@EmilioMBumachar are you referring to the N=1 example? The direction being clockwise vs counter-clockwise not N, S, E and W. – jacksonecac – 2016-10-04T18:41:24.883
@LuisMendo thank you! I lurked for a long time :) – jacksonecac – 2016-10-04T18:45:02.953
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 – 2016-10-04T19:04:32.540
@Rod Ok I'll keep it open awhile. I wasn't sure the protocol for these :) – jacksonecac – 2016-10-04T19:09:36.867