14
\$\begingroup\$

There are some iron particles on a board. We pass a current carrying wire through that board and the particles form circles. Show these circles if input given is the position of the wire.

Consider the board to be a grid of size 7x7 (fixed)

No extra white spaces are allowed.

Input can be 0-indexed or 1-indexed. (0-indexed in examples)

Examples

input:3,3 # 'X' is wire here but can be shown by anything other than '\/|-'
output:
/-----\
|/---\|
||/-\||
|||X|||
||\-/||
|\---/|
\-----/

input:1,2
output:
|/-\|||
||X||||
|\-/|||
\---/||
-----/|
------/
-------

input:0,0
output:
X||||||
-/|||||
--/||||
---/|||
----/||
-----/|
------/

input:0,3
output:
|||X|||
||\-/||
|\---/|
\-----/
-------
-------
-------

input:3,0
output:
---\|||
--\||||
-\|||||
X||||||
-/|||||
--/||||
---/|||

This is code-golf so shortest code wins.

\$\endgroup\$
  • \$\begingroup\$ Can the function output a 7x7 matrix with the characters or we need to print it on the console ? \$\endgroup\$ – digEmAll Dec 12 '18 at 15:00
7
\$\begingroup\$

J, 40 bytes

7 7{.6 6&-|.0":<^:6@8[9!:7@'/_\___\_/|-'

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks! \$\endgroup\$ – Galen Ivanov Dec 12 '18 at 14:09
5
\$\begingroup\$

R, 136 119 116 bytes

function(i,j,m=diag(7),R=row(m)-i,a=j-col(m)){m[]='-'
m[R==a]='\\'
m[R==-a]='/'
m[R<a&R>-a|R>a&-R>a]='|'
m[i,j]=0
m}

Try it online!

  • -3 bytes saved thanks to @Giuseppe

Function that takes (row,col) coordinates of the wire (1-indexed) and returns a 7x7 matrix with the characters.

\$\endgroup\$
3
\$\begingroup\$

Canvas, 27 23 22 21 bytes

-7×[\+]↶ω⟳n↔┼⁷⁸╵77@↕↔

Try it here!

\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES7),  105  103 bytes

Takes input as (y)(x), 0-indexed.

Y=>X=>(g=x=>y<7?`/\\-|X
`[h=(X-x)**2,v=(Y-y)**2,x<7?h<v?2:h>v?3:h?x<X^y<Y:4:5]+g(x<7?x+1:!++y):'')(y=0)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Perl 6, 90 bytes

{<| v - \ X />[1+([-]($_>>.abs).sign||3+[*]($_).sign)for ^7-$^a X ^7-$^b].rotor(7)>>.join}

Try it online!

Anonymous code block that takes two numbers and returns a list of lines.

\$\endgroup\$
1
\$\begingroup\$

Python 2, 105 bytes

lambda x,y:[''.join(['/-|'[cmp(abs(i-x),abs(j-y))],'\X'[i==x]][i-x==y-j]for j in R)for i in R]
R=range(7)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Charcoal, 21 bytes

GL⁷-↙⁶X‖B↘¬‖J±N±NT⁷¦⁷

Try it online! Takes 0-indexed column and row as input. Explanation:

GL⁷-

Draw a triangle of -s.

↙⁶

Draw a line along the hypotenuse. (This is the wrong way around but we'll fix that later.)

X

Draw the X that shows the position of the wire. (Any other ASCII character could be used here of course.) This completes one eighth of the drawing.

‖B↘¬

Reflect three times (¬ = left + down) while transforming characters to almost complete the diagram.

Reflect without transforming to switch the /s with the \s so they now point around the X instead of towards it.

J±N±N

Jump to the top left of the desired output.

T⁷¦⁷

Trim the result to the desired size.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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