A Slashy Dashy Spiral

3

Given a positive integer N, output the innermost N×N square of an ASCII art spiral made of -|/\ that spirals clockwise inward.

The - is used for horizontal portions, | for vertical portions, and / and \ for corners. The first character is - and the spiral proceeds left and down.

Specifically, when N is 1 the output is:

-

When N is 2 the output is:

/-
\-

When N is 3 the output is:

--\
/-|
\-/

When N is 4 the output is:

 /--\
 |/-|
 |\-/
 \---

Note how every output is a square of N by N characters.

The pattern continues in the same way:

N=1
-

N=2
/-
\-

N=3
--\
/-|
\-/

N=4
/--\
|/-|
|\-/
\---

N=5
----\
/--\|
|/-||
|\-/|
\---/

N=6
/----\
|/--\|
||/-||
||\-/|
|\---/
\-----

N=7
------\
/----\|
|/--\||
||/-|||
||\-/||
|\---/|
\-----/

N=8
/------\
|/----\|
||/--\||
|||/-|||
|||\-/||
||\---/|
|\-----/
\-------

etc.

The shortest code in bytes wins.

Calvin's Hobbies

Posted 2017-10-04T00:34:45.490

Reputation: 84 000

Question was closed 2017-10-04T11:30:06.590

Answers

6

Charcoal, 17 16 bytes:

↶⁴-F⊖N«↶²/ι↶²\-ι

Try it online! Link is to verbose version of code.

↷²-¶F⊖N«/ι↶²\-ι↶

Try it online! Link is to verbose version of code.

Edit: Saved 1 byte thanks to @icrieverytim.

Neil

Posted 2017-10-04T00:34:45.490

Reputation: 95 035

Aw shoot, I got ninja'd. ;-; Anyways, 16 bytes.

– totallyhuman – 2017-10-04T01:06:19.603

2@icrieverytim Oh, I forgot about Decremented, it's too new. – Neil – 2017-10-04T01:08:06.530

Neil are you the creator of Charcoal? – Jonah – 2017-10-04T02:46:35.867

1

@Jonah ASCII-only, along with DLosc, created Charcoal.

– totallyhuman – 2017-10-04T04:32:44.423

4

Python 2, 148 134 bytes

f=lambda n,J=''.join:n<2and['-']or n%2and['-'*~-n+'\\']+map(J,zip(f(n-1),'|'*(n-2)+'/'))or map(J,zip('/'+'|'*n,f(n-1)))+['\\'+'-'*~-n]

Try it online!

Chas Brown

Posted 2017-10-04T00:34:45.490

Reputation: 8 959