Draw this diamond pattern









up vote
16
down vote

favorite
3












The below pattern will form the basis of this challenge.



 /
/
/
/
/
// /
/ //
/
/
/
/
/


Given an input width and height, each >=1, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.



For example, here is an input with width = 2 and height = 1:



 / /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /


Here is an input width = 3 and height = 2:



 / / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /


Rules and I/O



  • Input and output can be given by any convenient method.

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.









share|improve this question





















  • Loosely related
    – Luis Mendo
    yesterday














up vote
16
down vote

favorite
3












The below pattern will form the basis of this challenge.



 /
/
/
/
/
// /
/ //
/
/
/
/
/


Given an input width and height, each >=1, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.



For example, here is an input with width = 2 and height = 1:



 / /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /


Here is an input width = 3 and height = 2:



 / / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /


Rules and I/O



  • Input and output can be given by any convenient method.

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.









share|improve this question





















  • Loosely related
    – Luis Mendo
    yesterday












up vote
16
down vote

favorite
3









up vote
16
down vote

favorite
3






3





The below pattern will form the basis of this challenge.



 /
/
/
/
/
// /
/ //
/
/
/
/
/


Given an input width and height, each >=1, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.



For example, here is an input with width = 2 and height = 1:



 / /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /


Here is an input width = 3 and height = 2:



 / / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /


Rules and I/O



  • Input and output can be given by any convenient method.

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.









share|improve this question













The below pattern will form the basis of this challenge.



 /
/
/
/
/
// /
/ //
/
/
/
/
/


Given an input width and height, each >=1, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.



For example, here is an input with width = 2 and height = 1:



 / /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /


Here is an input width = 3 and height = 2:



 / / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /


Rules and I/O



  • Input and output can be given by any convenient method.

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.






code-golf ascii-art






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









AdmBorkBork

25.4k362223




25.4k362223











  • Loosely related
    – Luis Mendo
    yesterday
















  • Loosely related
    – Luis Mendo
    yesterday















Loosely related
– Luis Mendo
yesterday




Loosely related
– Luis Mendo
yesterday










6 Answers
6






active

oldest

votes

















up vote
5
down vote














Canvas, 26 25 24 21 bytes



4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶


Try it here!



Explanation:



4/ create a 4-long diagonal
╬ quad-palindromize it - big inner diamond
/╬ quad-palindromize "/" - small diamond
⁰r center the two added vertically
:⤢n overlap with its transpose
⁷{ for each input:

╵× repeat the canvas input+1 times horizontally
↔ reverse horizontally
¹ the input,
A× times 10,
├ plus 2
m mold the canvas to that width
↶ rotate the canvas anti-clockwise, setting up for the other input





share|improve this answer





























    up vote
    5
    down vote













    JavaScript (ES8), 167 161 159 bytes



    Takes input as (width)(height).



    w=>h=>(g=h=>h?g(--h)+`
    `+([4106,4016,31305,21504,17010]['0102344320'[h%=10]]+'').replace(/./g,c=>'\/'[c^h>5]||''.padEnd(c-1)).repeat(w+1).slice(8):'')(h*10+2)


    Try it online!



    How?



    We encode the upper half of the pattern with digits:




    • $0$ means


    • $1$ means /


    • $n=2$ to $7$ means $n-1$ spaces

    This gives:



    0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
    1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
    0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
    2 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
    3 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
    4 /······/ --> [/] [6 spaces] [] [/] [] --> 17010


    For the lower half, we use the rows $4,3,2,0$ with / and inverted.






    share|improve this answer





























      up vote
      2
      down vote














      Perl 5 -p, 148 bytes





      $_='3A3'x$_.$/.'3B3
      3A3
      2/2\2
      1/4\1
      A6A
      B6B
      1\4/1
      2\2/2
      3B3
      3A3
      '=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm


      Try it online!






      share|improve this answer



























        up vote
        2
        down vote














        Haskell, 179 bytes





        k '\'='/'
        k '/'='\'
        k x=x
        f x=take(10*x+2)
        w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]


        Try it online!





        Haskell, 181 bytes





        k '\'='/'
        k '/'='\'
        k x=x
        f x=take(10*x+2)
        w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$map t[49200,36058,31630,30010,29038]
        t 0=""
        t n="\ /"!!mod n 3:t(div n 3)


        Try it online!






        share|improve this answer





























          up vote
          2
          down vote














          Charcoal, 24 23 bytes



          ´/↘²‖C↘‖MLF⊖NCχ⁰F⊖NC⁰χ


          Try it online! Link is to verbose version of code. Explanation:



          ´/↘²


          Draw one eighth of the original pattern.



          ‖C↘


          Duplicate it to make one quarter of the original pattern.



          ‖ML


          Duplicate it twice more to complete the original pattern.



          F⊖NCχ⁰


          Copy the required number of times horizontally.



          F⊖NC⁰χ


          Copy the required number of times vertically.



          Note: I think ‖M↘L should work for a two-byte saving but a) M↘ crashes and b) M↖ doesn't crash but appears to produce incorrect output.






          share|improve this answer





























            up vote
            0
            down vote













            JavaScript (ES6), 139 bytes



            This is using quite a different approach from my initial answer, so I'm posting this separately.



            Takes input as (width)(height).





            w=>h=>(g=x=>y>8?` /\
            `[a=(x+y*9)%10,b=(x+y)%10,x?(y%10>3&&2*(a==8)|b==5)|(y%10<6&&2*(a==6)|b==7):3]+g(x--?x:--y&&w):'')(w=w*10+2,y=-~h*10)


            Try it online!





            share




















              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%2f175619%2fdraw-this-diamond-pattern%23new-answer', 'question_page');

              );

              Post as a guest






























              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote














              Canvas, 26 25 24 21 bytes



              4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶


              Try it here!



              Explanation:



              4/ create a 4-long diagonal
              ╬ quad-palindromize it - big inner diamond
              /╬ quad-palindromize "/" - small diamond
              ⁰r center the two added vertically
              :⤢n overlap with its transpose
              ⁷{ for each input:

              ╵× repeat the canvas input+1 times horizontally
              ↔ reverse horizontally
              ¹ the input,
              A× times 10,
              ├ plus 2
              m mold the canvas to that width
              ↶ rotate the canvas anti-clockwise, setting up for the other input





              share|improve this answer


























                up vote
                5
                down vote














                Canvas, 26 25 24 21 bytes



                4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶


                Try it here!



                Explanation:



                4/ create a 4-long diagonal
                ╬ quad-palindromize it - big inner diamond
                /╬ quad-palindromize "/" - small diamond
                ⁰r center the two added vertically
                :⤢n overlap with its transpose
                ⁷{ for each input:

                ╵× repeat the canvas input+1 times horizontally
                ↔ reverse horizontally
                ¹ the input,
                A× times 10,
                ├ plus 2
                m mold the canvas to that width
                ↶ rotate the canvas anti-clockwise, setting up for the other input





                share|improve this answer
























                  up vote
                  5
                  down vote










                  up vote
                  5
                  down vote










                  Canvas, 26 25 24 21 bytes



                  4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶


                  Try it here!



                  Explanation:



                  4/ create a 4-long diagonal
                  ╬ quad-palindromize it - big inner diamond
                  /╬ quad-palindromize "/" - small diamond
                  ⁰r center the two added vertically
                  :⤢n overlap with its transpose
                  ⁷{ for each input:

                  ╵× repeat the canvas input+1 times horizontally
                  ↔ reverse horizontally
                  ¹ the input,
                  A× times 10,
                  ├ plus 2
                  m mold the canvas to that width
                  ↶ rotate the canvas anti-clockwise, setting up for the other input





                  share|improve this answer















                  Canvas, 26 25 24 21 bytes



                  4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶


                  Try it here!



                  Explanation:



                  4/ create a 4-long diagonal
                  ╬ quad-palindromize it - big inner diamond
                  /╬ quad-palindromize "/" - small diamond
                  ⁰r center the two added vertically
                  :⤢n overlap with its transpose
                  ⁷{ for each input:

                  ╵× repeat the canvas input+1 times horizontally
                  ↔ reverse horizontally
                  ¹ the input,
                  A× times 10,
                  ├ plus 2
                  m mold the canvas to that width
                  ↶ rotate the canvas anti-clockwise, setting up for the other input






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  dzaima

                  13.8k21653




                  13.8k21653




















                      up vote
                      5
                      down vote













                      JavaScript (ES8), 167 161 159 bytes



                      Takes input as (width)(height).



                      w=>h=>(g=h=>h?g(--h)+`
                      `+([4106,4016,31305,21504,17010]['0102344320'[h%=10]]+'').replace(/./g,c=>'\/'[c^h>5]||''.padEnd(c-1)).repeat(w+1).slice(8):'')(h*10+2)


                      Try it online!



                      How?



                      We encode the upper half of the pattern with digits:




                      • $0$ means


                      • $1$ means /


                      • $n=2$ to $7$ means $n-1$ spaces

                      This gives:



                      0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                      1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
                      0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                      2 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
                      3 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
                      4 /······/ --> [/] [6 spaces] [] [/] [] --> 17010


                      For the lower half, we use the rows $4,3,2,0$ with / and inverted.






                      share|improve this answer


























                        up vote
                        5
                        down vote













                        JavaScript (ES8), 167 161 159 bytes



                        Takes input as (width)(height).



                        w=>h=>(g=h=>h?g(--h)+`
                        `+([4106,4016,31305,21504,17010]['0102344320'[h%=10]]+'').replace(/./g,c=>'\/'[c^h>5]||''.padEnd(c-1)).repeat(w+1).slice(8):'')(h*10+2)


                        Try it online!



                        How?



                        We encode the upper half of the pattern with digits:




                        • $0$ means


                        • $1$ means /


                        • $n=2$ to $7$ means $n-1$ spaces

                        This gives:



                        0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                        1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
                        0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                        2 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
                        3 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
                        4 /······/ --> [/] [6 spaces] [] [/] [] --> 17010


                        For the lower half, we use the rows $4,3,2,0$ with / and inverted.






                        share|improve this answer
























                          up vote
                          5
                          down vote










                          up vote
                          5
                          down vote









                          JavaScript (ES8), 167 161 159 bytes



                          Takes input as (width)(height).



                          w=>h=>(g=h=>h?g(--h)+`
                          `+([4106,4016,31305,21504,17010]['0102344320'[h%=10]]+'').replace(/./g,c=>'\/'[c^h>5]||''.padEnd(c-1)).repeat(w+1).slice(8):'')(h*10+2)


                          Try it online!



                          How?



                          We encode the upper half of the pattern with digits:




                          • $0$ means


                          • $1$ means /


                          • $n=2$ to $7$ means $n-1$ spaces

                          This gives:



                          0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                          1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
                          0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                          2 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
                          3 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
                          4 /······/ --> [/] [6 spaces] [] [/] [] --> 17010


                          For the lower half, we use the rows $4,3,2,0$ with / and inverted.






                          share|improve this answer














                          JavaScript (ES8), 167 161 159 bytes



                          Takes input as (width)(height).



                          w=>h=>(g=h=>h?g(--h)+`
                          `+([4106,4016,31305,21504,17010]['0102344320'[h%=10]]+'').replace(/./g,c=>'\/'[c^h>5]||''.padEnd(c-1)).repeat(w+1).slice(8):'')(h*10+2)


                          Try it online!



                          How?



                          We encode the upper half of the pattern with digits:




                          • $0$ means


                          • $1$ means /


                          • $n=2$ to $7$ means $n-1$ spaces

                          This gives:



                          0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                          1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
                          0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
                          2 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
                          3 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
                          4 /······/ --> [/] [6 spaces] [] [/] [] --> 17010


                          For the lower half, we use the rows $4,3,2,0$ with / and inverted.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 13 hours ago

























                          answered yesterday









                          Arnauld

                          68k584288




                          68k584288




















                              up vote
                              2
                              down vote














                              Perl 5 -p, 148 bytes





                              $_='3A3'x$_.$/.'3B3
                              3A3
                              2/2\2
                              1/4\1
                              A6A
                              B6B
                              1\4/1
                              2\2/2
                              3B3
                              3A3
                              '=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm


                              Try it online!






                              share|improve this answer
























                                up vote
                                2
                                down vote














                                Perl 5 -p, 148 bytes





                                $_='3A3'x$_.$/.'3B3
                                3A3
                                2/2\2
                                1/4\1
                                A6A
                                B6B
                                1\4/1
                                2\2/2
                                3B3
                                3A3
                                '=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm


                                Try it online!






                                share|improve this answer






















                                  up vote
                                  2
                                  down vote










                                  up vote
                                  2
                                  down vote










                                  Perl 5 -p, 148 bytes





                                  $_='3A3'x$_.$/.'3B3
                                  3A3
                                  2/2\2
                                  1/4\1
                                  A6A
                                  B6B
                                  1\4/1
                                  2\2/2
                                  3B3
                                  3A3
                                  '=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm


                                  Try it online!






                                  share|improve this answer













                                  Perl 5 -p, 148 bytes





                                  $_='3A3'x$_.$/.'3B3
                                  3A3
                                  2/2\2
                                  1/4\1
                                  A6A
                                  B6B
                                  1\4/1
                                  2\2/2
                                  3B3
                                  3A3
                                  '=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm


                                  Try it online!







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 23 hours ago









                                  Xcali

                                  4,890520




                                  4,890520




















                                      up vote
                                      2
                                      down vote














                                      Haskell, 179 bytes





                                      k '\'='/'
                                      k '/'='\'
                                      k x=x
                                      f x=take(10*x+2)
                                      w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]


                                      Try it online!





                                      Haskell, 181 bytes





                                      k '\'='/'
                                      k '/'='\'
                                      k x=x
                                      f x=take(10*x+2)
                                      w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$map t[49200,36058,31630,30010,29038]
                                      t 0=""
                                      t n="\ /"!!mod n 3:t(div n 3)


                                      Try it online!






                                      share|improve this answer


























                                        up vote
                                        2
                                        down vote














                                        Haskell, 179 bytes





                                        k '\'='/'
                                        k '/'='\'
                                        k x=x
                                        f x=take(10*x+2)
                                        w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]


                                        Try it online!





                                        Haskell, 181 bytes





                                        k '\'='/'
                                        k '/'='\'
                                        k x=x
                                        f x=take(10*x+2)
                                        w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$map t[49200,36058,31630,30010,29038]
                                        t 0=""
                                        t n="\ /"!!mod n 3:t(div n 3)


                                        Try it online!






                                        share|improve this answer
























                                          up vote
                                          2
                                          down vote










                                          up vote
                                          2
                                          down vote










                                          Haskell, 179 bytes





                                          k '\'='/'
                                          k '/'='\'
                                          k x=x
                                          f x=take(10*x+2)
                                          w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]


                                          Try it online!





                                          Haskell, 181 bytes





                                          k '\'='/'
                                          k '/'='\'
                                          k x=x
                                          f x=take(10*x+2)
                                          w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$map t[49200,36058,31630,30010,29038]
                                          t 0=""
                                          t n="\ /"!!mod n 3:t(div n 3)


                                          Try it online!






                                          share|improve this answer















                                          Haskell, 179 bytes





                                          k '\'='/'
                                          k '/'='\'
                                          k x=x
                                          f x=take(10*x+2)
                                          w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]


                                          Try it online!





                                          Haskell, 181 bytes





                                          k '\'='/'
                                          k '/'='\'
                                          k x=x
                                          f x=take(10*x+2)
                                          w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$map t[49200,36058,31630,30010,29038]
                                          t 0=""
                                          t n="\ /"!!mod n 3:t(div n 3)


                                          Try it online!







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited 10 hours ago

























                                          answered yesterday









                                          ovs

                                          18.1k21058




                                          18.1k21058




















                                              up vote
                                              2
                                              down vote














                                              Charcoal, 24 23 bytes



                                              ´/↘²‖C↘‖MLF⊖NCχ⁰F⊖NC⁰χ


                                              Try it online! Link is to verbose version of code. Explanation:



                                              ´/↘²


                                              Draw one eighth of the original pattern.



                                              ‖C↘


                                              Duplicate it to make one quarter of the original pattern.



                                              ‖ML


                                              Duplicate it twice more to complete the original pattern.



                                              F⊖NCχ⁰


                                              Copy the required number of times horizontally.



                                              F⊖NC⁰χ


                                              Copy the required number of times vertically.



                                              Note: I think ‖M↘L should work for a two-byte saving but a) M↘ crashes and b) M↖ doesn't crash but appears to produce incorrect output.






                                              share|improve this answer


























                                                up vote
                                                2
                                                down vote














                                                Charcoal, 24 23 bytes



                                                ´/↘²‖C↘‖MLF⊖NCχ⁰F⊖NC⁰χ


                                                Try it online! Link is to verbose version of code. Explanation:



                                                ´/↘²


                                                Draw one eighth of the original pattern.



                                                ‖C↘


                                                Duplicate it to make one quarter of the original pattern.



                                                ‖ML


                                                Duplicate it twice more to complete the original pattern.



                                                F⊖NCχ⁰


                                                Copy the required number of times horizontally.



                                                F⊖NC⁰χ


                                                Copy the required number of times vertically.



                                                Note: I think ‖M↘L should work for a two-byte saving but a) M↘ crashes and b) M↖ doesn't crash but appears to produce incorrect output.






                                                share|improve this answer
























                                                  up vote
                                                  2
                                                  down vote










                                                  up vote
                                                  2
                                                  down vote










                                                  Charcoal, 24 23 bytes



                                                  ´/↘²‖C↘‖MLF⊖NCχ⁰F⊖NC⁰χ


                                                  Try it online! Link is to verbose version of code. Explanation:



                                                  ´/↘²


                                                  Draw one eighth of the original pattern.



                                                  ‖C↘


                                                  Duplicate it to make one quarter of the original pattern.



                                                  ‖ML


                                                  Duplicate it twice more to complete the original pattern.



                                                  F⊖NCχ⁰


                                                  Copy the required number of times horizontally.



                                                  F⊖NC⁰χ


                                                  Copy the required number of times vertically.



                                                  Note: I think ‖M↘L should work for a two-byte saving but a) M↘ crashes and b) M↖ doesn't crash but appears to produce incorrect output.






                                                  share|improve this answer















                                                  Charcoal, 24 23 bytes



                                                  ´/↘²‖C↘‖MLF⊖NCχ⁰F⊖NC⁰χ


                                                  Try it online! Link is to verbose version of code. Explanation:



                                                  ´/↘²


                                                  Draw one eighth of the original pattern.



                                                  ‖C↘


                                                  Duplicate it to make one quarter of the original pattern.



                                                  ‖ML


                                                  Duplicate it twice more to complete the original pattern.



                                                  F⊖NCχ⁰


                                                  Copy the required number of times horizontally.



                                                  F⊖NC⁰χ


                                                  Copy the required number of times vertically.



                                                  Note: I think ‖M↘L should work for a two-byte saving but a) M↘ crashes and b) M↖ doesn't crash but appears to produce incorrect output.







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited 15 mins ago

























                                                  answered yesterday









                                                  Neil

                                                  77.5k744174




                                                  77.5k744174




















                                                      up vote
                                                      0
                                                      down vote













                                                      JavaScript (ES6), 139 bytes



                                                      This is using quite a different approach from my initial answer, so I'm posting this separately.



                                                      Takes input as (width)(height).





                                                      w=>h=>(g=x=>y>8?` /\
                                                      `[a=(x+y*9)%10,b=(x+y)%10,x?(y%10>3&&2*(a==8)|b==5)|(y%10<6&&2*(a==6)|b==7):3]+g(x--?x:--y&&w):'')(w=w*10+2,y=-~h*10)


                                                      Try it online!





                                                      share
























                                                        up vote
                                                        0
                                                        down vote













                                                        JavaScript (ES6), 139 bytes



                                                        This is using quite a different approach from my initial answer, so I'm posting this separately.



                                                        Takes input as (width)(height).





                                                        w=>h=>(g=x=>y>8?` /\
                                                        `[a=(x+y*9)%10,b=(x+y)%10,x?(y%10>3&&2*(a==8)|b==5)|(y%10<6&&2*(a==6)|b==7):3]+g(x--?x:--y&&w):'')(w=w*10+2,y=-~h*10)


                                                        Try it online!





                                                        share






















                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote









                                                          JavaScript (ES6), 139 bytes



                                                          This is using quite a different approach from my initial answer, so I'm posting this separately.



                                                          Takes input as (width)(height).





                                                          w=>h=>(g=x=>y>8?` /\
                                                          `[a=(x+y*9)%10,b=(x+y)%10,x?(y%10>3&&2*(a==8)|b==5)|(y%10<6&&2*(a==6)|b==7):3]+g(x--?x:--y&&w):'')(w=w*10+2,y=-~h*10)


                                                          Try it online!





                                                          share












                                                          JavaScript (ES6), 139 bytes



                                                          This is using quite a different approach from my initial answer, so I'm posting this separately.



                                                          Takes input as (width)(height).





                                                          w=>h=>(g=x=>y>8?` /\
                                                          `[a=(x+y*9)%10,b=(x+y)%10,x?(y%10>3&&2*(a==8)|b==5)|(y%10<6&&2*(a==6)|b==7):3]+g(x--?x:--y&&w):'')(w=w*10+2,y=-~h*10)


                                                          Try it online!






                                                          share











                                                          share


                                                          share










                                                          answered 1 min ago









                                                          Arnauld

                                                          68k584288




                                                          68k584288



























                                                               

                                                              draft saved


                                                              draft discarded















































                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function ()
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175619%2fdraw-this-diamond-pattern%23new-answer', 'question_page');

                                                              );

                                                              Post as a guest














































































                                                              這個網誌中的熱門文章

                                                              How to read a connectionString WITH PROVIDER in .NET Core?

                                                              In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                                                              Museum of Modern and Contemporary Art of Trento and Rovereto