Iron particles around a magnet

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












14














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
    Dec 12 at 15:00















14














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
    Dec 12 at 15:00













14












14








14


1





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 Dec 12 at 12:26









Vedant Kandoi

1,073226




1,073226











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
















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















Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
Dec 12 at 15:00




Can the function output a 7x7 matrix with the characters or we need to print it on the console ?
– digEmAll
Dec 12 at 15:00










7 Answers
7






active

oldest

votes


















7















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
    Dec 12 at 14:09


















5















R, 136 119 116 bytes





function(i,j,m=diag(7),R=row(m)-i,a=j-col(m))R>a&-R>a]='


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.






share|improve this answer






























    3















    Canvas, 27 23 22 21 bytes



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


    Try it here!






    share|improve this answer






























      1














      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






























        1















        Perl 6, 90 bytes








        Try it online!



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






        share|improve this answer






























          1















          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




























            0















            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.






            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',
              autoActivateHeartbeat: false,
              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

























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              7















              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
                Dec 12 at 14:09















              7















              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
                Dec 12 at 14:09













              7












              7








              7







              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 Dec 12 at 12:51









              FrownyFrog

              2,4471518




              2,4471518











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
















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















              Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
              – Galen Ivanov
              Dec 12 at 14:09




              Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!
              – Galen Ivanov
              Dec 12 at 14:09











              5















              R, 136 119 116 bytes





              function(i,j,m=diag(7),R=row(m)-i,a=j-col(m))R>a&-R>a]='


              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.






              share|improve this answer



























                5















                R, 136 119 116 bytes





                function(i,j,m=diag(7),R=row(m)-i,a=j-col(m))R>a&-R>a]='


                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.






                share|improve this answer

























                  5












                  5








                  5







                  R, 136 119 116 bytes





                  function(i,j,m=diag(7),R=row(m)-i,a=j-col(m))R>a&-R>a]='


                  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.






                  share|improve this answer















                  R, 136 119 116 bytes





                  function(i,j,m=diag(7),R=row(m)-i,a=j-col(m))R>a&-R>a]='


                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 15 at 15:54

























                  answered Dec 12 at 14:18









                  digEmAll

                  2,43148




                  2,43148





















                      3















                      Canvas, 27 23 22 21 bytes



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


                      Try it here!






                      share|improve this answer



























                        3















                        Canvas, 27 23 22 21 bytes



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


                        Try it here!






                        share|improve this answer

























                          3












                          3








                          3







                          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 Dec 12 at 14:27

























                          answered Dec 12 at 14:00









                          dzaima

                          14.4k21754




                          14.4k21754





















                              1














                              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



























                                1














                                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

























                                  1












                                  1








                                  1






                                  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 Dec 12 at 13:03

























                                  answered Dec 12 at 12:51









                                  Arnauld

                                  72.3k689303




                                  72.3k689303





















                                      1















                                      Perl 6, 90 bytes








                                      Try it online!



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






                                      share|improve this answer



























                                        1















                                        Perl 6, 90 bytes








                                        Try it online!



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






                                        share|improve this answer

























                                          1












                                          1








                                          1







                                          Perl 6, 90 bytes








                                          Try it online!



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






                                          share|improve this answer















                                          Perl 6, 90 bytes








                                          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 Dec 12 at 13:11

























                                          answered Dec 12 at 13:04









                                          Jo King

                                          20.7k246109




                                          20.7k246109





















                                              1















                                              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

























                                                1















                                                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























                                                  1












                                                  1








                                                  1







                                                  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 Dec 12 at 13:44









                                                  TFeld

                                                  14.1k21240




                                                  14.1k21240





















                                                      0















                                                      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.






                                                      share|improve this answer

























                                                        0















                                                        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.






                                                        share|improve this answer























                                                          0












                                                          0








                                                          0







                                                          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.






                                                          share|improve this answer













                                                          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.







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Dec 12 at 21:36









                                                          Neil

                                                          79.2k744177




                                                          79.2k744177



























                                                              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

                                                              How to check contact read email or not when send email to Individual?

                                                              Bahrain

                                                              Postfix configuration issue with fips on centos 7; mailgun relay