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.










share|improve this question






















  • Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
    – digEmAll
    1 hour ago















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.










share|improve this question






















  • Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
    – digEmAll
    1 hour ago













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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










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!






share|improve this answer





















  • Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
    – Galen Ivanov
    2 hours ago


















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).






share|improve this answer






























    up vote
    3
    down vote














    Canvas, 27 23 22 21 bytes



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


    Try it here!






    share|improve this answer






























      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!






      share|improve this answer






























        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.






        share|improve this answer






























          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!






          share|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "200"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            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

























            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!






            share|improve this answer





















            • Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
              – Galen Ivanov
              2 hours ago















            up vote
            5
            down vote














            J, 40 bytes



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


            Try it online!






            share|improve this answer





















            • Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
              – Galen Ivanov
              2 hours ago













            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!






            share|improve this answer













            J, 40 bytes



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


            Try it online!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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


















            • 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










            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).






            share|improve this answer



























              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).






              share|improve this answer

























                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).






                share|improve this answer















                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).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 1 hour ago









                digEmAll

                2,30148




                2,30148






















                    up vote
                    3
                    down vote














                    Canvas, 27 23 22 21 bytes



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


                    Try it here!






                    share|improve this answer



























                      up vote
                      3
                      down vote














                      Canvas, 27 23 22 21 bytes



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


                      Try it here!






                      share|improve this answer

























                        up vote
                        3
                        down vote










                        up vote
                        3
                        down vote










                        Canvas, 27 23 22 21 bytes



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


                        Try it here!






                        share|improve this answer















                        Canvas, 27 23 22 21 bytes



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


                        Try it here!







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 1 hour ago

























                        answered 2 hours ago









                        dzaima

                        14.3k21754




                        14.3k21754






















                            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!






                            share|improve this answer



























                              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!






                              share|improve this answer

























                                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!






                                share|improve this answer














                                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!







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 3 hours ago

























                                answered 3 hours ago









                                Arnauld

                                71.2k688298




                                71.2k688298






















                                    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.






                                    share|improve this answer



























                                      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.






                                      share|improve this answer

























                                        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.






                                        share|improve this answer















                                        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.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited 3 hours ago

























                                        answered 3 hours ago









                                        Jo King

                                        20.3k245107




                                        20.3k245107






















                                            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!






                                            share|improve this answer

























                                              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!






                                              share|improve this answer























                                                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!






                                                share|improve this answer













                                                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!







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 2 hours ago









                                                TFeld

                                                14k21240




                                                14k21240






























                                                    draft saved

                                                    draft discarded




















































                                                    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.




                                                    draft saved


                                                    draft discarded














                                                    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





















































                                                    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







                                                    Popular posts from this blog

                                                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                                                    How to ignore python UserWarning in pytest?

                                                    Alexandru Averescu