Iron particles around a magnet
up vote
5
down vote
favorite
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.
code-golf ascii-art
add a comment |
up vote
5
down vote
favorite
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.
code-golf ascii-art
Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
1 hour ago
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
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.
code-golf ascii-art
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.
code-golf ascii-art
code-golf ascii-art
asked 3 hours ago
Vedant Kandoi
1,008224
1,008224
Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
1 hour ago
add a comment |
Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
1 hour ago
Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
1 hour ago
Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
1 hour ago
add a comment |
6 Answers
6
active
oldest
votes
up vote
5
down vote
J, 40 bytes
7 7{.6 6&-|.0":<^:6@8[9!:7@'/_____/|-'
Try it online!
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
add a comment |
up vote
5
down vote
R, 136 bytes
function(j,i,m=diag(7),R=row(m),C=col(m),a=i+j-C,b=i-j+C){m='|'
m[R==a]='\'
m[R==b]='/'
m[R<a&R>b|R>a&R<b]='-'
m[i,j]=0
write(m,1,7)}
Try it online!
Function that takes (row,col) coordinates of the center (1-indexed).
add a comment |
up vote
3
down vote
Canvas, 27 23 22 21 bytes
-7×[+]↶ω⟳n↔┼⁷⁸╵77@↕↔
Try it here!
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
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!
add a comment |
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
J, 40 bytes
7 7{.6 6&-|.0":<^:6@8[9!:7@'/_____/|-'
Try it online!
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
add a comment |
up vote
5
down vote
J, 40 bytes
7 7{.6 6&-|.0":<^:6@8[9!:7@'/_____/|-'
Try it online!
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
add a comment |
up vote
5
down vote
up vote
5
down vote
J, 40 bytes
7 7{.6 6&-|.0":<^:6@8[9!:7@'/_____/|-'
Try it online!
J, 40 bytes
7 7{.6 6&-|.0":<^:6@8[9!:7@'/_____/|-'
Try it online!
answered 3 hours ago
FrownyFrog
2,4171518
2,4171518
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
add a comment |
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
– Galen Ivanov
2 hours ago
add a comment |
up vote
5
down vote
R, 136 bytes
function(j,i,m=diag(7),R=row(m),C=col(m),a=i+j-C,b=i-j+C){m='|'
m[R==a]='\'
m[R==b]='/'
m[R<a&R>b|R>a&R<b]='-'
m[i,j]=0
write(m,1,7)}
Try it online!
Function that takes (row,col) coordinates of the center (1-indexed).
add a comment |
up vote
5
down vote
R, 136 bytes
function(j,i,m=diag(7),R=row(m),C=col(m),a=i+j-C,b=i-j+C){m='|'
m[R==a]='\'
m[R==b]='/'
m[R<a&R>b|R>a&R<b]='-'
m[i,j]=0
write(m,1,7)}
Try it online!
Function that takes (row,col) coordinates of the center (1-indexed).
add a comment |
up vote
5
down vote
up vote
5
down vote
R, 136 bytes
function(j,i,m=diag(7),R=row(m),C=col(m),a=i+j-C,b=i-j+C){m='|'
m[R==a]='\'
m[R==b]='/'
m[R<a&R>b|R>a&R<b]='-'
m[i,j]=0
write(m,1,7)}
Try it online!
Function that takes (row,col) coordinates of the center (1-indexed).
R, 136 bytes
function(j,i,m=diag(7),R=row(m),C=col(m),a=i+j-C,b=i-j+C){m='|'
m[R==a]='\'
m[R==b]='/'
m[R<a&R>b|R>a&R<b]='-'
m[i,j]=0
write(m,1,7)}
Try it online!
Function that takes (row,col) coordinates of the center (1-indexed).
edited 1 hour ago
answered 1 hour ago
digEmAll
2,30148
2,30148
add a comment |
add a comment |
up vote
3
down vote
Canvas, 27 23 22 21 bytes
-7×[+]↶ω⟳n↔┼⁷⁸╵77@↕↔
Try it here!
add a comment |
up vote
3
down vote
Canvas, 27 23 22 21 bytes
-7×[+]↶ω⟳n↔┼⁷⁸╵77@↕↔
Try it here!
add a comment |
up vote
3
down vote
up vote
3
down vote
Canvas, 27 23 22 21 bytes
-7×[+]↶ω⟳n↔┼⁷⁸╵77@↕↔
Try it here!
Canvas, 27 23 22 21 bytes
-7×[+]↶ω⟳n↔┼⁷⁸╵77@↕↔
Try it here!
edited 1 hour ago
answered 2 hours ago
dzaima
14.3k21754
14.3k21754
add a comment |
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
up vote
1
down vote
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!
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!
edited 3 hours ago
answered 3 hours ago
Arnauld
71.2k688298
71.2k688298
add a comment |
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
up vote
1
down vote
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.
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.
edited 3 hours ago
answered 3 hours ago
Jo King
20.3k245107
20.3k245107
add a comment |
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
up vote
1
down vote
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!
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!
answered 2 hours ago
TFeld
14k21240
14k21240
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177429%2firon-particles-around-a-magnet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
1 hour ago