3
\$\begingroup\$

This question already has an answer here:

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.

\$\endgroup\$

marked as duplicate by Calvin's Hobbies, Toto, Gryphon, Erik the Outgolfer code-golf Oct 4 '17 at 11:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Aw shoot, I got ninja'd. ;-; Anyways, 16 bytes. \$\endgroup\$ – totallyhuman Oct 4 '17 at 1:06
  • 2
    \$\begingroup\$ @icrieverytim Oh, I forgot about Decremented, it's too new. \$\endgroup\$ – Neil Oct 4 '17 at 1:08
  • \$\begingroup\$ Neil are you the creator of Charcoal? \$\endgroup\$ – Jonah Oct 4 '17 at 2:46
  • 1
    \$\begingroup\$ @Jonah ASCII-only, along with DLosc, created Charcoal. \$\endgroup\$ – totallyhuman Oct 4 '17 at 4:32
4
\$\begingroup\$

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!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.