17
\$\begingroup\$

Your challenge is to exactly output the following box:

..................................................
..................................................
..                                              ..
..                                              ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++                                      ++  ..
..  ++                                      ++  ..
..  ++  ..................................  ++  ..
..  ++  ..................................  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..................................  ++  ..
..  ++  ..................................  ++  ..
..  ++                                      ++  ..
..  ++                                      ++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..                                              ..
..                                              ..
..................................................
..................................................

The box is height and width 50, spaces are two wide.

You must write a function or program which outputs or returns a string and takes no input.

Fewest bytes wins!

\$\endgroup\$
  • 4
    \$\begingroup\$ Any reason why the innermost + box only has 1 layer at the top and bottom? That'll make algorithm-based answers somewhat longer, as it means the innermost two layers aren't exactly square. \$\endgroup\$ – ETHproductions Jan 13 '17 at 17:34
  • \$\begingroup\$ @Pavel OK. Close-vote retracted :) \$\endgroup\$ – Digital Trauma Jan 13 '17 at 17:44
  • 4
    \$\begingroup\$ Why the restriction on a complete program? \$\endgroup\$ – Rɪᴋᴇʀ Jan 13 '17 at 18:30
  • 1
    \$\begingroup\$ @Pavel why? It adds really nothing to the challenge. \$\endgroup\$ – Rɪᴋᴇʀ Jan 13 '17 at 20:41
  • 1
    \$\begingroup\$ @Pavel .....no. I mean yeah some have that, but it's not by far a requirement/standard for KG challenges. \$\endgroup\$ – Rɪᴋᴇʀ Jan 13 '17 at 20:54

20 Answers 20

9
\$\begingroup\$

Pyke, 20 17 bytes

k25V". + "ohe@A.X

Try it here!

k                 - out = ""
 25V              - repeat 25 times:
          oh      -     (o++)+1
            e     -    ^//2
    ". + "   @    -   " + ."[^] (wraps around)
              A.X -  out = surround(out, ^)

The surround function was made for questions like this!

\$\endgroup\$
14
\$\begingroup\$

J, 25 bytes

echo'. + '{~4|>./~2#|i:12

Try it online!

Explanation

echo'. + '{~4|>./~2#|i:12
                     i:12  Range from -12 to 12.
                    |      Take absolute values,
                  2#       duplicate every element,
                /~         compute "multiplication table"
              >.           using maximum,
            4|             take mod 4 of every element,
    '. + '{~               index into this string,
echo                       print char matrix for everyone to see.
\$\endgroup\$
  • \$\begingroup\$ I think you can leave off the echo. \$\endgroup\$ – Conor O'Brien Jan 13 '17 at 21:12
  • \$\begingroup\$ @ConorO'Brien Oh, the output rule changed. ...Hmm, but if I remove echo, it won't be even a function, just a value. Although J doesn't have zero-argument functions anyway. \$\endgroup\$ – Zgarb Jan 13 '17 at 21:21
  • \$\begingroup\$ I think that's allowed as per J's repl nature. In any case, constant functions can be considered to be zero-argument. \$\endgroup\$ – Conor O'Brien Jan 13 '17 at 21:45
11
\$\begingroup\$

C, 115 bytes

#define M(x,y)x<(y)?x:y
f(i){for(i=2549;i;i--)putchar(i%51?". + "[(M(i%51-1,M(50-i%51,M(i/51,49-i/51))))/2%4]:10);}

Defines a function f (call as f();) that prints the string to STDOUT.

\$\endgroup\$
9
\$\begingroup\$

C, 535 478 477 Bytes

Now that's a lot of golf :-/

i;main(j){for(;++i<51;puts(""))for(j=0;++j<51;)putchar(i<3|i>48?46:j<3|j>48?46:i>4&i<47&j>4&j<47?i<7|(i>44&i<47)|(j>2&j<7)|(j>44&j<47)?43:j>8&j<43&((i>8&i<11)|(i>40&i<43))?46:i>9&i<41&((j>8&j<11)|(j>40&j<43))?46:i>13&i<37&((j>12&j<15)|(j>36&j<39))?43:((i>12&i<15)|(i>36&i<39))&j>12&j<39?43:i>17&i<33&((j>16&j<19)|(j>32&j<35))?46:((i>16&i<19)|(i>32&i<35))&j>16&j<35?46:i>21&i<29&((j>20&j<23)|(j>28&j<31))?43:((i>20&i<23)|(i>28&i<31))&j>20&j<31?43:i>24&i<27&j>24&j<27?46:32:32);}

Here's the output;

..................................................
..................................................
..                                              ..
..                                              ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++                                      ++  ..
..  ++                                      ++  ..
..  ++  ..................................  ++  ..
..  ++  ..................................  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..................................  ++  ..
..  ++  ..................................  ++  ..
..  ++                                      ++  ..
..  ++                                      ++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..                                              ..
..                                              ..
..................................................
..................................................
\$\endgroup\$
  • 2
    \$\begingroup\$ Holy shit. I admire your dedication. \$\endgroup\$ – Rɪᴋᴇʀ Jan 13 '17 at 20:54
  • \$\begingroup\$ I've changed the restriction, functions which return a string are allowed now. \$\endgroup\$ – Pavel Jan 13 '17 at 20:59
  • \$\begingroup\$ I just realized I can golf a few bytes out re-writing the loops for(;i++<51; and now I'm off by one everywhere :-/ \$\endgroup\$ – cleblanc Jan 13 '17 at 21:00
  • \$\begingroup\$ @cleblanc ++i \$\endgroup\$ – dkudriavtsev Jan 14 '17 at 10:39
  • \$\begingroup\$ MFW I started trying to understand this: i.imgur.com/TLV9gJ4.png +1 \$\endgroup\$ – Magic Octopus Urn Jan 19 '17 at 18:32
6
\$\begingroup\$

Haskell, 72 bytes

q=(\n->[n,n]).abs=<<[-12..12]
unlines[[". + "!!mod(max x y)4|y<-q]|x<-q]

@Zgarb's solution in Haskell. I've also tried to construct the box by adding layers around the core ["..",".."], but it is 9 bytes longer (81 bytes).

e!b=e:e:b++[e,e];s#c=(c!)<$>(c<$s!!0)!s
unlines$foldl(#)["..",".."]" + . + . + ."
\$\endgroup\$
5
\$\begingroup\$

Stacked, noncompeting, 35 bytes

Try it here!

ε'.'3$' + .'2*tostr*+$surroundfold

Ungolfed:

'' '.  ++  ..  ++  ..  ++  ..' $surround fold

Quite simple. surround is a function that, well, surrounds an entity with a fill entity. For example, (0) 1 surround is ((1 1 1) (1 0 1) (1 1 1)). $surround is surround as a function, not evaluated. fold takes an initial value, then something to fold over, then a function. In this case, surround is folded, surrounding the initially empty string '' (equiv. ε) with each character of the string.

'.'3$' + .'2*tostr*+

This is first making a character string $' + .', that, when multiplied by a number, repeats each character. This leaves us with: ++ ... This is then casted to a string. Then, we repeat this string thrice, and finally prepend a ., giving us the desired string.


A different approach for 39 bytes:

' .'3$' + .'2*tostr*+toarr$surround#\out

#\ is insert and takes the initial char of the string as the starting value. It also only works on Arrays.

\$\endgroup\$
  • \$\begingroup\$ How is this noncompeting, the challenge went up only a few hours ago. \$\endgroup\$ – Pavel Jan 14 '17 at 3:07
  • \$\begingroup\$ @Pavel I'm always working on this \$\endgroup\$ – Conor O'Brien Jan 14 '17 at 3:17
4
\$\begingroup\$

JavaScript (ES6), 117 bytes

f=(n=12,c=`. + `[n%4],t=c.repeat(n*4+2))=>n?t+`
${t}
${f(n-1).replace(/^|$/gm,c+c)}
${t}
`+t:`..
..`
console.log(f())

Nonrecursive solution took me 128 bytes:

console.log([...Array(100)].map((_,i,a)=>a.map((_,j)=>`. + `[j=j>50?j-50:51-j,(i>j?i:j)%8>>1],i=i>50?i-50:51-i).join``).join`\n`)

Where \n represents the literal newline character.

\$\endgroup\$
4
\$\begingroup\$

C, 97 bytes

i,x,y;main(){for(;i<2550;putchar(++i%51?". + "[(x*x<y*y?y:x)&3]:10))x=i%51/2-12,y=i/102-12;}
\$\endgroup\$
3
\$\begingroup\$

Jelly, 18 bytes

12ŒRAx2»þ`ị“ + .”Y

Try it online!

Same approach as Zgarb’s J answer: 12ŒRA is abs([-12 … 12]), x2 repeats every element twice, »þ` creates a table of maximums, ị“ + .” cyclically indexes into a string, and Y joins by newlines.

\$\endgroup\$
3
\$\begingroup\$

05AB1E, 39 35 33 bytes

•â3fM~•3B…012… .+‡.pvyD¤sg25s-׫«})«»

Try it online!

•â3fM~•3B                               # Push 1100220011002200110022001
         …012… .+‡                      # Push ..  ++  ..  ++  ..  ++  .
                  .p                    # All prefixes of the above string.
                    vy            }     # For each prefix.
                      D¤sg25s-×         # Repeat the last letter until length is 25.
                               «Â«      # Concat, bifurcate, concat.
                                   )«» # Wrap to array, bifurcate, concat, print.

33 Byte version that is cooler now because Emigna commented saving me 2 bytes:

". + "DøJ3×'.«.pvy¤25yg-׫«})«»

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ ". + "DøJ3×'.«.pvy¤25yg-׫«})«» for 33 bytes. \$\endgroup\$ – Emigna Jan 19 '17 at 19:17
  • \$\begingroup\$ … .+•â3fM~•3BSè.pvy¤25yg-׫«})«» for 34 bytes on the "cooler version". \$\endgroup\$ – Emigna Jan 19 '17 at 19:20
  • \$\begingroup\$ Cool was not the correct choice of word haha. "Less Ghetto", maybe? \$\endgroup\$ – Magic Octopus Urn Jan 19 '17 at 19:36
  • \$\begingroup\$ I do love your use of the prefix command. Brilliant! \$\endgroup\$ – Emigna Jan 19 '17 at 20:06
  • 1
    \$\begingroup\$ @Emigna the prefixes make a triangle, if you transpose the triangle and rotate it, then combine it with the original prefixes you may be able to shave off bytes. That was the main plan that I couldn't get at. \$\endgroup\$ – Magic Octopus Urn Jan 19 '17 at 20:56
2
\$\begingroup\$

MATL, 21 bytes

'. + '[]25:"TTYaQ]2/)

Try it online!

'. + '    % Push this string
[]        % Push empty array. This will be used as "seed"
25:"      % Do the following 25 times
  TTYa    %   Extend the array with a frame of zeros
  Q       %   Add 1 to each entry
]         % End
2/        % Divide by 2
)         % Index modularly into the string. Non-integer indices are rounded
          % Implicitly display
\$\endgroup\$
2
\$\begingroup\$

Ruby, 77 bytes

-623.upto(676){|i|print i%26>0?". + "[[(i%26-13).abs,(i/52).abs].max%4]*2:$/}
\$\endgroup\$
  • \$\begingroup\$ I think you can replace the index expression with [i%26-13,i/52].map(&:abs).max%4 (saves a byte) \$\endgroup\$ – Conor O'Brien Jan 19 '17 at 1:22
2
\$\begingroup\$

Charcoal, 25 bytes

F…¹¦²⁶⁺×ι§. + ÷鲶‖O↗‖C↑←

Try it online! Link contains verbose mode for explanation

\$\endgroup\$
2
\$\begingroup\$

Python 3, 89 bytes

r=range(-24,26)
for i in r:print("".join([". + "[max(abs(i//2),abs(j//2))%4]for j in r]))

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Haskell, 385 Bytes

    b 0 = ["..", ".."]
b n = f:f:s:s:m (b (n - 1)) ++s:s:f:f:[]
    where f = replicate (8*n+2) $ d
          s = l++replicate ((8*n)-6) ' ' ++r
          m (x:xs) = map (\x -> l ++ x ++ r ) $ t
          l = d:d:' ':' ':[]
          r = reverse l
          t = b (n - 1)
          d :: Char
          d | n `mod` 2 == 0 = '.'
            | n `mod` 2 == 1 = '+'
main = mapM_ putStrLn $ b 6

First round of code golf here... looking forward to seeing how others tackle this one.

Output:

..................................................
..................................................
..                                              ..
..                                              ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++                                      ++  ..
..  ++                                      ++  ..
..  ++  ..................................  ++  ..
..  ++  ..................................  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++      ++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..  ++++++++++  ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..              ..  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++  ..................  ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++                      ++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..  ++++++++++++++++++++++++++  ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..                              ..  ++  ..
..  ++  ..................................  ++  ..
..  ++  ..................................  ++  ..
..  ++                                      ++  ..
..  ++                                      ++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..  ++++++++++++++++++++++++++++++++++++++++++  ..
..                                              ..
..                                              ..
..................................................
..................................................
\$\endgroup\$
  • 3
    \$\begingroup\$ 1) You have tons of unnecessary whitespace. 2) put all function definitions within the where into a single line and use ; for separation . 3) f:f:[] is f:[f] and d:' ':' ':[]` is d:" ". 4) m takes a parameter but doesn't use it. Inline m and t. 5) define a new function # to replace replicate: c#x=c<$[1..8*n+x] and call it like d#2 and ' '#(-6). 6) mod 2 == 0 can be replaced with even, or flip the test and use odd and the golfer's otherwise: 1<2. ... \$\endgroup\$ – nimi Jan 14 '17 at 11:53
  • 2
    \$\begingroup\$ ... all in all: b n=f:f:s:s:map(\x->l++x++r)(b$n-1)++s:s:f:[f]where f=d#2;s=l++' '#(-6)++r;l=d:d:" ";r=reverse l;d|odd n='+'|1<2='.';c#x=c<$[1..8*n+x]. \$\endgroup\$ – nimi Jan 14 '17 at 11:53
1
\$\begingroup\$

Octave, 53 bytes

 '.  ++  .'(mod(bsxfun(@max,x=[24:-1:0 0:24],x'),8)+1)

Generate repeating pattern of 1 to 8 from center outward and use it as the index for extraction of elements of . ++ .

Try It Online!

\$\endgroup\$
1
\$\begingroup\$

Bash, 191 bytes

echo H4sIAGUcgFgAA73VOw7AIAyD4b2n6F6J+x+v6k5CnPy1F6ZPAvNaS80li4/cUvrkKWdGapOak3O5DDmVS5G8XI5k5ZIkLpclUbk02ZfLk125f5B4JIljLY59cZwxx31x3H3HO5aFIo7/pZIpqWZClHSJmg55AeBhTxb2CQAA|base64 -d|gunzip

Can probably get smaller, but was smaller than my algorithmic attempts.

\$\endgroup\$
1
\$\begingroup\$

C#, 203 bytes

Complete, readable program:

using System;
public class P
{
    public static void Main(string[] a)
    {
        Func<string> f = () =>
        {
            var z = 25;
            var t = "";
            Func<int, string> c = (q) => q % 4 == 0 ? ".." : (q % 4 != 2 ? "  " : "++");
            for (var y = 0; y < z; y++)
            {
                var l = "";
                for (var x = 0; x < z; x++)
                        l += ((y > z / 2) ? (x >= y | x < z - y) : (x < y | x >= z - y)) ? c(x):c(y);
                l += "\n";
                t += l + l;
            }
            return t;
        };

        Console.Write(f());
        Console.ReadKey();
    }
}

Golfed function:

()=>{var z=25;var t="";Func<int,string>c=(q)=>q%4==0?"..":(q%4!=2?"  ":"++");for(var y=0;y<z;y++){var l="";for(var x=0;x<z;x++)l+=((y>z/2)?(x>=y|x<z-y):(x<y|x>=z-y))?c(x):c(y);l+="\n";t+=l+l;}return t;};
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 33 bytes

14G" . +"NL¤¸13N-.׫€D¨Â«èD})¨Â«»

Try it online!

Explanation

14G                               # for N in [1 ... 13]
   " . +"                         # push this string
         NL                       # push range [1 ... N]
           ¤¸13N-.×               # push a list of 13-N repetitions 
                                  # of the last element of the above range
                   «              # concatenate the two ranges
                    €D            # duplicate each element
                      ¨           # remove the last element
                       «         # concatenate a reversed copy to the list
                         è        # use the elements of the list to index into the string
                          D       # duplicate the resulting string
                           }      # end loop
                            )     # wrap the strings in a list
                             ¨    # remove the last element
                              «  # concatenate a reversed copy
                                » # join the list on newlines
\$\endgroup\$
  • \$\begingroup\$ Explanation to come? \$\endgroup\$ – Pavel Jan 19 '17 at 20:52
  • \$\begingroup\$ @Pavel: of course! :) \$\endgroup\$ – Emigna Jan 19 '17 at 20:54
1
\$\begingroup\$

PowerShell, 171 151 bytes

($x=(1..12|%{' . +'[$_%4]}|%{($a+=$_+$_)})+"$a."|%{$c=if(++$i%2){('+','.')[($b=!$b)]}else{' '};$_.PadRight(25,$c)}|%{,($_+-join$_[25..0])*2});$x[23..0]

Try it online!

Ho-hum answer. I'm sure there's a shorter way (given the lengths of the other answers, I'm confident), but this shows some neat tricks.

Explanation:

1..12|%{' . +'[$_%4]} generates an array of strings (of one character in length), in the correct pattern we need. Try it online!

We then add on |%{($a+=$_+$_)})+"$a." which takes the array and expands it sideways based on the previous row. Try it online!

Those strings are then sent into a loop, |%{$c=if(++$i%2){('+','.')[($b=!$b)]}else{' '};$_.PadRight(25,$c)}. Each iteration, we're choosing the correct character (either a plus, a dot, or a space), and then using the .PadRight function to pad out to the appropriate number of characters. Try it online!

Now, we have the foundation of the upper-right corner. We need to reverse each string |%{,($_+-join$_[($z=25..0)])*2} and append them together so we can get the top of the block. This is done with the -join command and indexing backward 25..0. Additionally, we encapsulate the strings in an array ,(...) and make 'em double *2 so we get the whole top. Try it online!

That is all stored into $x and encapsulated in parens so it places the strings on the pipeline. Finally, we reverse $x (being sure to snip out the duplicate-duplicate middle row, else we'd have four .. in the middle) and leave those on the pipeline. An implicit Write-Output sticks a newline between the strings, so we get that for free.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.