Print this text:

 _________
|         |
|         |
|         |
|_________|

Shortest code wins. Notice the space at the start of the first line.

  • 16
    Welcome to PPCG. Is there anything that makes this challenge interesting compared to all the other kolmogorov-complexity challenges we already have? – Adám Nov 28 at 22:39

18 Answers 18

Charcoal, 12 bytes

←×⁵_↑⁴ ×⁵_‖O

Try it online! Link is to verbose version of code. Sadly the vertical direction is insufficiently symmetric to make it worthwhile reflecting. Explanation:

←×⁵_

Print 5 _s, leaving the cursor to the left of the first _. This makes up half of the bottom of the square.

↑⁴

Print 4 |s upwards, making the left of the square.

 ×⁵_

Print a space and 5 _s, making half of the top of the square.

‖O

Reflect to complete the square.

PowerShell, 40 37 bytes

" "+($x="_"*9)
,"|$(" "*9)|"*3
"|$x|"

Try it online!

Canvas, 9 bytes

I×⁹-x~‰‟│

Try it here!

Compression. Less boring 12-byte answer:

2|*5_×+⇵ ∔↕╪

2|*           repeat "|" vertically 2 times
   5_×        repeat "_" horizontally 5 times
      +       add the two together horizontally
       ⇵      reverse the canvas vertically
         ∔    prepend a space (because otherwise it glitches out :|)
          ↕   reverse vertically, moving the underscores up
           ╪  quad-palindromize, moving underscores as needed

Try it here!

05AB1E, 24 22 21 bytes

ð'_9׫ð9×'|.ø4и`ð'_:»

Try it online!

  • Dangit Okx.. And here I was so happy with my Canvas answer being shorter than the compression I usually use for KC challenges. +1 though, nice shorter alternative! – Kevin Cruijssen Nov 29 at 8:23
  • Btw, you can remove the ©, since you don't use it anywhere. And the 5 should be a 4. PS: If you want to use the Elixir rewrite instead of Python legacy, replace the * with ×. Multiply with strings coincidentally works in the Python legacy version, but was never intended to. Bit of a bug disguised as 'feature'. – Kevin Cruijssen Nov 29 at 8:28
  • @KevinCruijssen Fixed and golfed off a byte – Okx Nov 29 at 8:36
  • 2
    My biggest problem with the new 05AB1E is that the debug feature is terrible – Okx Nov 29 at 8:39
  • Yeah, I can only agree on that.. I switch a lot back to the legacy in order to use -d. You do get a bit more information when using --debug-stack instead of -d in the Elixir rewrite version, but still not as much or as good as with the legacy debugger -d.. – Kevin Cruijssen Nov 29 at 8:41

Python 2, 41 bytes

a=' '
for b in'_   _':print a+9*b+a;a='|'

Try it online!

Changes the outer character from ' ' to '|' after the first line using an assignment, a simple trick I don't remember seeing in an ASCII art golf before.

J, 24 bytes

<3 9$LF[9!:7' |_'#~6 4 1

Try it online!

Canvas, 19 bytes

“5+║³╵∑O:E`}7╴?B<‟│

Try it here!

  • oh, there was already a canvas compression answer.. Either way the input string to compression I gave was " _____¶|¶|¶|¶|_____" - trailing spaces are automatically added, and splitting the input in multiple lines just worsens its compression ability – dzaima Nov 29 at 17:36

Python 2, 54, 53, 50, 48 bytes

print' '+'_'*9+'\n|         |'*3+'\n|_________|'

-1 Thanks to Kevin Cruijssen.

-3 Thanks to Okx

-2 Thanks to Vedant Kandoi

  • You can remove the trailing space on the first line (+' \n' to +'\n') to save a byte. – Kevin Cruijssen Nov 29 at 8:58
  • @KevinCruijssen whoops! Thanks for spotting that! – Henry T Nov 29 at 9:00
  • 2
    50 bytes if you move around the newlines: print' '+'_'*9+('\n|'+' '*9+'|')*4+'\n|'+'_'*9+'|' – Okx Nov 29 at 9:36
  • 48 bytes: print' '+'_'*9+'\n| |'*5+'\n|_________|', 9 spaces between | and | – Vedant Kandoi Nov 29 at 9:51
  • @Okx ahh good spot! – Henry T Nov 29 at 11:30

05AB1E, 27 21 bytes (using compression and mirror)

…_ |•ʒßKèËß•3вèJ5ä».º

Straightforward approach.

Try it online.

Explanation:

…_ |        # Push string "_ |"
•ʒßKèËß•    # Push compressed integer 68865864629382
 3в         # Convert to Base-3 as list
            #  [1,0,0,0,0,0,2,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,2,0,0,0,0,0]
   è        # Index each into the string
            #  [" ","_","_","_","_","_","|"," "," "," "," "," ","|"," "," "," "," "," ","|"," "," "," "," "," ","|","_","_","_","_","_"]
    J       # Join all characters together
            #  " _____|     |     |     |_____"
     5ä     # Split the string into 5 equal-sized substrings
            #  [" _____","|     ","|     ","|     ","|_____"]
       »    # Join them by newlines
            #  " _____\n|     \n|     \n|     \n|_____"
        .º  # Mirror with overlap (and output implicitly)
            #  " _________ \n|         |\n|         |\n|         |\n|_________|\n"

See this 05AB1E tip of mine (section How to compress integer lists?) to understand why •ʒßKèËß•3в is [1,0,0,0,0,0,2,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,2,0,0,0,0,0].


05AB1E, 28 26 bytes (using the Canvas)

'_9∍ð'|4∍JDðKðJŽWêSÌsŽ9¦SΛ

I like this approach a lot more, but unfortunately it's a bit longer.. This approach uses the Canvas builtin Λ.

Try it online.

Explanation:

'_9∍      '# Push string "_" and enlarge it to size 9: "_________"
ð          # Push a space character
'|4∍      '# Push string "|" and enlarge it to size 4: "||||"
J          # Join the entire stack together to a single string
D          # Duplicate it
ðK         # Remove the space
ð          # Push a space character
J          # Join all the entire stack together to a single string
           # (We now have "_________ ||||_________|||| ")
ŽWê        # Push compressed integer 8393
   S       # Convert it to a list of digits: [8,3,9,3]
    Ì      # Add 2 to each: [10,5,11,5]
s          # Swap the list and string on the stack
Ž9¦        # Push compressed integer 2460
   S       # Convert it to a list of digits: [2,4,6,0]
Λ          # Use the Canvas with options (and output immediately implicitly):
           #  [10,5,11,5] as lengths
           #  "_________ ||||_________|||| " as string to draw
           #  [2,4,6,0] as directions, which is [left,down,right,up] respectively

Here a few alternatives for creating the strings ('_9∍ð'|4∍JDðKðJ) with the same amount of bytes:

MathGolf, 27 bytes

'_9*_3{'|_ 9*▌+\}'|_@++]n \

Try it online!

Pretty much the simplest way to do it.

Java 11, 57 bytes

v->" _________\n"+"|         |\n".repeat(3)+"|_________|"

Try it online.

I don't think this requires an explanation.. >.>

  • Hi, I am new to golfing. Can you explain where is the print statement here? Thank for your help. – isaace Nov 29 at 14:30
  • @isaace Hi there and welcome to PPCG! We have some default rules that apply to all challenges (unless explicitly stated differently). For example, these loopholes are forbidden by default; and you are allowed to use any default I/O method. This means that you are allowed to use functions instead of full programs, and you're also allowed to return a string instead of printing something to STDOUT directly. Since Java is pretty verbose, I use both those alternatives in my answer. – Kevin Cruijssen Nov 29 at 14:35
  • ok, thank you for the explanation! – isaace Nov 29 at 14:37
  • @isaace The shortest full program that prints directly to STDOUT would have been interface M{static void main(String[]a){System.out.print(" _________\n"+"| |\n".repeat(3)+"|_________|");}}. Since all Java programs need a mandatory main method and enclosing class/interface, it's (almost) always shorter to use a (Java 8+ lambda) function instead. In addition, it's shorter to return a String instead of printing with System.out.print in this case. Hope that clears it up a bit. :) – Kevin Cruijssen Nov 29 at 14:37

JavaScript, 54 bytes

As with Kevin's Java solution, the boring option ended up being the shortest :\

_=>` _________
${`|         |
`.repeat(3)}|_________|`

Try It Online


Alternative, 59 bytes

_=>` _
| |
| |
| |
|_|`.replace(/../g,x=>x.padEnd(10,x[1]))

Try It Online

05AB1E, 19 bytes

ŽP—S"_| _"SŽNžS.Λ.º

Try it online!

Explanation

ŽP—S                  # push [6,5,2,5] (lengths)
    "_| _"S           # push ["_", "|", " ", "_"] (characters to print)
           ŽNžS       # push [6,0,2,2] (directions)
               .Λ     # draw to canvas without printing
                 .º   # mirror horizontally

C# (.NET Core), 66 bytes

Console.Write(" {0}\n|{1}{1}{1}{0}|","_________","         |\n|");

Try it online!

  • Prints the first argument of Console.Write()
  • {0} refers to the second argument ("_________")
  • {1} refers to the third argument (" |\n|").

Java, 59 Bytes

v-> " _______\n|       |\n|       |\n|       |\n|_______|"
  • 1
    Should this be embedded in a function or something? – Jo King Nov 29 at 16:04

Red, 53 bytes

prin[" _________^/"r:"|         |^/"r r"|_________|"]

Try it online!

Brain-Flak, 317 bytes

((((((((()()()()()){}){})()){}{}){}))<>)<>((((((((({}[(((()()()){}()){}){}()])))))))))(<>{}<>)((()()()()()){})(<>()()()){<>(((((((()()()()()){}){})()){}{}){})<>)<> ((((((((((((()()()()){}){}){})))))))))(<>{}<>)((()()()()()){})<>({}[()])}<>(((((()()()()){}){}){}))((((((((((({})){}{}[()])))))))))((((()()()()){}){}){})

Try it online!

Not golfy at all, just a test.

R, 55 bytes

cat(gsub(0,"|         |
"," _________
000|_________|"))

Try it online!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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