Embedded Diamonds!

27

6

No, not this. And not this either. This question is nothing like those

Write the shortest code to print/return the following output:

   /\      /\      /\
  /  \    /  \    /  \
 / /\ \  / /\ \  / /\ \
/ /  \ \/ /  \ \/ /  \ \
\ \  / /\ \  / /\ \  / /
 \ \/ /  \ \/ /  \ \/ /
  \  / /\ \  / /\ \  /
   \/ /  \ \/ /  \ \/
   /\ \  / /\ \  / /\
  /  \ \/ /  \ \/ /  \
 / /\ \  / /\ \  / /\ \
/ /  \ \/ /  \ \/ /  \ \
\ \  / /\ \  / /\ \  / /
 \ \/ /  \ \/ /  \ \/ /
  \  /    \  /    \  /
   \/      \/      \/
  • Standard methods of input/output.
  • Standard loopholes apply.
  • Trailing/leading whitespace is okay, in any amount.

Comrade SparklePony

Posted 2017-05-04T23:03:10.740

Reputation: 5 784

3

Not this, Not that, What about this?

– Matthew Roh – 2017-05-05T10:37:02.250

Answers

14

Charcoal, 28 24 23 bytes

↗²↖↙⁴⟲P²⁴⁶↘↙↙²⟲P²⁴⁶C⁸¦⁰

Try it online! Explanation:

↗²↖↙⁴   Draw the top left 4x4 corner
         /
        //
⟲P²⁴⁶   Rotate it three times to complete a diamond
         /\
        //\\
        \\//
         \/
↘↙↙²    Draw the top left line of the inner diamond
         /\
        //\\
        \\//
         \//
⟲P²⁴⁶   Rotate three times to complete five diamonds
C⁸¦⁰    Copy everything 8 characters to the right to complete eight diamonds

Edit: My previous answer used ‖M‖M↓ to create a whole diamond by reflecting the top corner, but due to a bug in Charcoal this left the cursor out of position. Fortunately I discovered another way of achieving the same effect which doesn't move the cursor, which meant that I saved a byte drawing the inner diamond. (I also looked into overlapping operations, but I wasn't able to improve on the rotate/copy approach.)

Edit: ↖²↗↘⁴‖M¬M¹¦³↘²‖M¬C⁸¦⁰ does the job in 21 bytes, but that relies on the new reflecting behaviour, so I don't know whether this was possible with the old code.

Neil

Posted 2017-05-04T23:03:10.740

Reputation: 95 035

Yeah, sorry, it was a bug - I've fixed it and will try to push ASAP, but this is still insanely short :O +1 – ASCII-only – 2017-05-07T01:52:32.187

@ASCII-only If I've been using TIO, how does that affect me? – Neil – 2017-05-07T09:33:03.793

Well, it's still cached, so as long as it is cached, it should be fine if that's what you mean – ASCII-only – 2017-05-07T10:14:26.770

@ASCII-only What I want to know is that when TIO's behaviour changes I would like to be able to provide an updated (although non-competing) link. – Neil – 2017-05-07T10:16:54.880

Oh, in that case it already has the fix – ASCII-only – 2017-05-07T10:17:49.300

@ASCII-only Ah, in that case, the cursor is still in a surprising place, but it doesn't change the length of the answer (currently the easiest "fix" is to change a to a ). – Neil – 2017-05-07T10:21:48.400

Let us continue this discussion in chat.

– ASCII-only – 2017-05-07T10:23:03.160

7

Charcoal, 62 50 48 45 42 40 bytes

Thanks to @Okx for saving two bytes!

↙²→↘²↙↖⁴→↗⁴‖MF²C⁸¦⁰M⁸↓→↗²↓↘²M⁴→↑↗²↓↘²‖M↓

Try it online!

Explanation:

↙²→↘²          // Draw the left half of the inner part of the first diamond.
↖⁴→↗⁴          // Draw the left half of the outer part.
‖M             // Mirror the half of the diamond to create the first full diamond.
F²C⁸¦⁰         // Copy the picture eight characters to the left twice.
               // The first copy gives us two diamonds, and the second copy of the
               // two diamonds overlaps so that the result is three diamonds.
M⁸↓→↗²↓↘²     // Move down to draw the upper inner half of the first middle diamond.
M⁴→↑↗²↓↘²     // Move right to do the same for the second middle diamond.
‖M↓           // Mirror the whole thing vertically.

Steadybox

Posted 2017-05-04T23:03:10.740

Reputation: 15 798

1You can replace C⁸¦⁰C⁸¦⁰ with F²C⁸¦⁰¦ to save a byte. – Okx – 2017-05-05T09:45:54.600

@Okx Thanks! Actually, this saves two bytes, because it works without the trailing ¦. – Steadybox – 2017-05-05T11:33:51.330

For the record, some update seems to have broken this, as the code no longer works properly on TIO. The answer still remains valid, because it worked with the version TIO was using back when this answer was posted. – Steadybox – 2017-11-27T22:09:20.913

6

05AB1E, 45 44 43 bytes

Code:

…/ \©•—‹íćCé']d₂2ó@¯çX‘¯¨•3вè8äJvy®‡«}»Â»

Pre-explanation:

The •—‹íćCé'\]d₂2ó@¯çX‘¯¨•3в part is just a compressed version of the following array:

[1, 1, 1, 0, 2, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 2, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 2, 1, 2, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 2, 1, 2, 0, 1, 0, 1, 2, 1, 2, 1, 1, 0, 1, 0, 2, 1, 2, 1, 1, 2, 1, 2, 0, 1, 0, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 0, 1, 0, 2, 1, 2, 1, 1, 1, 1, 2, 0, 1, 0, 1, 1, 2, 1, 2]

Which we index into the string …/ \. This maps 0 -> /, 1 -> space, 2 -> \. After that, we process this string with the following program:

8äJvy®‡«}»Â»

8ä               # Split the array into 8 pieces
  J              # Join each sub-array in the array
   vy     }      # For each string in the array
     Â           #   Bifurcate (duplicate and reverse)
      ®          #   Push the string "/ \" (which was copied using ©)
       Â         #   Bifurcate to get "\ /"
        ‡        #   Transliterate / -> \ and \ -> /
         «       #   Append to the original string
           »     # Join the entire stack on newlines
            Â    # Bifurcate
             »   # Join the stack by newlines

Uses the 05AB1E encoding. Try it online!

Adnan

Posted 2017-05-04T23:03:10.740

Reputation: 41 965

05AB1E is very good at ASCII-art, it seems... – Esolanging Fruit – 2017-05-05T02:10:40.180

4Crossed out fourty four is still fourty four. – Okx – 2017-05-05T09:44:41.133

@Okx Unless you apply non-breaking spaces.

– Steadybox – 2017-05-05T11:37:02.587

5

PHP, 126 Bytes

<?=gzinflate(base64_decode("vY7BCQAwCAP/mSIbuJD7z1GJLbbiuz5yKCeEpDk1RUSQWm8iMiRnIyw178Qgi5hs3ceHOA86snN7ON2b/687X+7umuIC"));

Try it online!

PHP, 149 Bytes

$s=strtr("000
111
222
333
444
555
  \ 22 /  
   \\33/   ",["   /\   ","  /  \  "," / /\ \ ","/ /  \ \\","\ \  / /"," \ \/ / "]);echo"$s
".strrev($s);

Try it online!

Jörg Hülsermann

Posted 2017-05-04T23:03:10.740

Reputation: 13 026

3

JavaScript, 232 bytes

_=>(a=`3868683
2/274/274/272
1/18172/18172/18171
/1/27191/27191/2717
7172/18172/18172/1/
17191/27191/27191/1
272/18172/18172/2
391/27191/27193`.replace(/\d/g,n=>n>6?['\\','/\\','\\/'][n-7]:' 
'.repeat(n)))+`
`+[...a].reverse().join``

Try it online!

const f = _=>(a=`3868683
2/274/274/272
1/18172/18172/18171
/1/27191/27191/2717
7172/18172/18172/1/
17191/27191/27191/1
272/18172/18172/2
391/27191/27193`.replace(/\d/g,n=>n>6?['\\','/\\','\\/'][n-7]:' '.repeat(n)))+`
`+[...a].reverse().join``

console.log(`
${f()}
`)

powelles

Posted 2017-05-04T23:03:10.740

Reputation: 1 277

I have a 126 byte solution below. :) – Steve Bennett – 2017-05-18T14:02:57.073

3

Ruby, 99 97 bytes

400.times{|i|print (23<x=i%25)?$/:" /  \\   "[(x^y=i/25)&4^x+y&1^(x-2&4&y-2>y/6%2*x/2%11*4?2:0)]}

Explanation

Each 4x4 square contains only spaces and / or \. We plot these to give the overall diamond pattern. To avoid partial patterns at the borders, certain 2x2 squares must be left blank as below.

.. /\ .... /\ .... /\ ..
../  \..../  \..../  \..
 / /\ \  / /\ \  / /\ \
/ /  \ \/ /  \ \/ /  \ \
\ \  / /\ \  / /\ \  / /
 \ \/ /  \ \/ /  \ \/ /
..\  / /\ \  / /\ \  /..
.. \/ /  \ \/ /  \ \/ ..
.. /\ \  / /\ \  / /\ ..
../  \ \/ /  \ \/ /  \..
 / /\ \  / /\ \  / /\ \
/ /  \ \/ /  \ \/ /  \ \
\ \  / /\ \  / /\ \  / /
 \ \/ /  \ \/ /  \ \/ /
..\  /....\  /....\  /..
.. \/ .... \/ .... \/ ..

Ungolfed version - modified to print the above to assist in explanation

400.times{|i|print (23<x=i%25)?$/:     #Calculate x. If last column, print a newline else
  " /..\\ .."[(x^y=i/25)&4^x+y&1^      #If (x^y)&4==4, use x+y&1 to select between space and /. If (x^y)&4==0 select between \ and space.
  (x-2&4&y-2>y/6%2*x/2%11*4?2:0)]      #If x-2&4&y-2==4, and we are on the 2 character wide border (y/6%2*x/2%11==0), XOR with 2 to print .
}

Level River St

Posted 2017-05-04T23:03:10.740

Reputation: 22 049

2

Pyth - 106 98 96 92 bytes

V16V24J%t+NH8K%+_2-NH8=Y&&&>H1>N1<N14<H22p?|q2J&&Y!%J4?<1%H4J!J\/?|q2K&&Y!%K4?<1%H4!KK\\d)pb

Try it

Maria

Posted 2017-05-04T23:03:10.740

Reputation: 644

1

C#, 608 bytes

void q(){Action<string>a=Console.Write;Func<int,int,string>b=(c,d)=>new string(' ',c)+(d<1?"/\\":d<2?"/  \\":d<3?"/ /\\ \\":d<4?"/ /  \\ \\":d<5?"\\ \\  / /":d<6?"\\ \\/ /":d<7?"\\  /":"\\/");Action e=()=>a(b(0,4)+b(0,4)+b(0,4)+"\n"+b(1,5)+b(2,5)+b(2,5)+"\n");Action f=()=>a(b(1,2)+b(2,2)+b(2,2)+"\n");Action g=()=>a(b(0,3)+b(0,3)+b(0,3)+"\n");a(b(3,0)+b(6,0)+b(6,0)+"\n"+b(2,1)+b(4,1)+b(4,1)+"\n");f();g();e();a("  \\  / /\\ \\  / /\\ \\  /\n"+"   \\/ /  \\ \\/ /  \\ \\/\n"+"   /\\ \\  / /\\ \\  / /\\\n"+"  /  \\ \\/ /  \\ \\/ /  \\\n");f();g();e();a(b(2,6)+b(4,6)+b(4,6)+"\n"+b(3,7)+b(6,7)+b(6,7)+"\n");}

LiefdeWen

Posted 2017-05-04T23:03:10.740

Reputation: 3 381

Not that I want to make this any longer but it looks like you're missing using System;. I'm also pretty sure you can golf this more but I haven't spent too much time looking to be 100% sure. – TheLethalCoder – 2017-05-18T08:11:44.587

Its longer than the output so just System.Console.WriteLine(@"..."); Will beat my answer by like 200 bytes. – LiefdeWen – 2017-05-18T08:20:00.480

1

Javascript 126 bytes

for(c=r=a='';r<16;c++>22&&(r++,c=0,a+=`
`))C=c%22>1&&r%14>1,q=[1,,C&&r&2,,,,C&&~r&2,,1],a+=q[c+5+r&7]?'/':q[r-c+20&7]?'\\':' '

Since it's now pretty unreadable, a basic explanation:

  • we tile the space top left to bottom right
  • we draw it as basically 6 diagonal lines that repeat every 8 characters: 2 solid lines, and 4 that are "dashed" (two characters, then two spaces...)
  • the C=... stuff is to limit drawing of some of the lines to within a bounding box
  • to save a lot of characters, we deliberately add numbers to make the expressions for the upwards and downwards lines extremely similar
  • then, put the expressions themselves into a sparse array [1,,C&&...], which we look up into. If there is a truthy value, we draw the appropriate character.

-

for(c=r=a='';r<16;c++>22&&(r++,c=0,a+=`
`))                 // basic grid tiling
C=c%22>1&&r%14>1,   // are we not near the edges
q=[1,               // a solid line that always draws
,                   // a line that never draws
C&&r&2,             // a line that draws if not near the edge, and if on the correct "dash" (r&2)
,,,
C&&~r&2,            // if not near the edge, and on the opposite "dash" (~r&2)
,1                  // the opposite diagonal line that always draws
],
a+=q[c+5+r&7]?'/' // compute which upward line we're on, check whether to draw it
:q[r-c+20&7]?'\\' // do the same for the downward line
:' '                // otherwise draw a space

Maybe this explanation didn't help. :)

Try online: https://codepen.io/stevebennett/pen/WjgMpY

Hopefully I got the output right:

   /\      /\      /\   
  /  \    /  \    /  \  
 / /\ \  / /\ \  / /\ \ 
/ /  \ \/ /  \ \/ /  \ \
\ \  / /\ \  / /\ \  / /
 \ \/ /  \ \/ /  \ \/ / 
  \  / /\ \  / /\ \  /  
   \/ /  \ \/ /  \ \/   
   /\ \  / /\ \  / /\   
  /  \ \/ /  \ \/ /  \  
 / /\ \  / /\ \  / /\ \ 
/ /  \ \/ /  \ \/ /  \ \
\ \  / /\ \  / /\ \  / /
 \ \/ /  \ \/ /  \ \/ / 
  \  /    \  /    \  /  
   \/      \/      \/   

History

130

for(c=r=a='';r<16;c++>22&&(r++,c=0,a+=`
`))C=c%22>1&&r%14>1,q=[1,,C&&r&2,,,,C&&~r&2,,1],a+=q[(c+5+r)%8]?'/':q[(r-c+20)%8]?'\\':' '

133

for(c=r=a='';r<16;c++>22&&(r++,c=0,a+=`
`))C=c%22>1,q=[1,,C&&r&2&&r<14,,,,C&&~r&2&&r>1,,1],a+=q[(c+5+r)%8]?'/':q[(r-c+20)%8]?'\\':' '

137

for(c=r=a='';r<16;c++==23&&(r++,c=0,a+=`
`))C=c<22&&c>1,q=[1,,C&&r&2&&r<14,,,,C&&~r&2&&r>1,,1],a+=q[(c+5+r)%8]?'/':q[(r-c+20)%8]?'\\':' '

155

for(c=r=a='';r<16;c++==23&&(r++,c=0,a+=`
`))Z=(C=c<22&&c>1)&&~r&2&&r>1,Y=C&&r&2&&r<14,B=(c-r+12)%8,A=(c+5+r)%8,q=[1,,Y,,,,Z,,1],a+=q[A]?'/':q[8-B]?'\\':' '

History: 172

for(c=r=a='';r<16;c++==23&&(r++,c=0,a+='\n'))a+=(Z=(C=c<22&&c>1)&&~r&2&&r>3,Y=C&&r&2&&r<12,B=(c-r+16)%8,A=(c+r)%8,A==3||A==5&&Y||A==1&&Z?'/':B==4||B==2&&Y||B==6&&Z?'\\':' ')

Steve Bennett

Posted 2017-05-04T23:03:10.740

Reputation: 1 558

1

C#, 382 291 bytes

_=>string.Format(@"{5}{5}{5}
{2}{2}{2}
{0}{0}{0}
{1}{1}{1}
\ \ {0}{0} / /
 \ \{1}{1}/ /
  \ {0}{0} /
   \{1}{1}/
   /\ \ {0} / /\
  /  \ \{1}/ /  \
 {0}{0}{0}
{1}{1}{1}
\ \ {0}{0} / /
 \ \{1}{1}/ /
{4}{4}{4}
{3}{3}{3}",@" / /\ \ ",@"/ /  \ \",@"  /  \  ",@"   \/   ",@"  \  /  ",@"   /\   ");

TheLethalCoder

Posted 2017-05-04T23:03:10.740

Reputation: 6 930

1

Canvas, 18 bytes

4/2/33╋╬2/77╋╬:91╋

Try it here!

Explanation:

4/           push a diagonal of length 4
  2/         push a diagonal of length 2
    33╋      insert that at [3;3] in the 1st diagonal
                    /
                   / 
                  / /
                 / / 
╬            quad-palindromize with 0 overlap
 2/77╋       insert a 2-long diagonal in the bottom-right corner
                    /\   
                   /  \  
                  / /\ \ 
                 / /  \ \
                 \ \  / /
                  \ \/ / 
                   \  / /
                    \/ / 
      ╬      quad-palindromize with 0 overlap, creating most of the output
                    /\      /\   
                   /  \    /  \  
                  / /\ \  / /\ \ 
                 / /  \ \/ /  \ \
                 \ \  / /\ \  / /
                  \ \/ /  \ \/ / 
                   \  / /\ \  /  
                    \/ /  \ \/   
                    /\ \  / /\   
                   /  \ \/ /  \  
                  / /\ \  / /\ \ 
                 / /  \ \/ /  \ \
                 \ \  / /\ \  / /
                  \ \/ /  \ \/ / 
                   \  /    \  /  
                    \/      \/   
       :91╋  overlap self on [9;1]

dzaima

Posted 2017-05-04T23:03:10.740

Reputation: 19 048

0

Retina, 214 bytes


F/\E/\E/\¶B/B\BB/B\FAD D¶F\/ C C¶FD D /\¶BC CAF\B/BB\B/¶F\/E\/E\/
F
B 
E
BBB
D
/\ \B/
C
/B\ \/
B
  
A
 /  \¶ / /\ \  / /\ \  / /\ \¶/ /  \ \/ /  \ \/ /  \ \¶\ \  / /\ \  / /\ \  / /¶ \ \/ /  \ \/ /  \ \/ /¶  \  / 

Try it online!

ovs

Posted 2017-05-04T23:03:10.740

Reputation: 21 408