# Print a square!

Print this text:

 _________
|         |
|         |
|         |
|_________|


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

• 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 '18 at 22:39

# PowerShell, 40 37 bytes

" "+($x="_"*9) ,"|$(" "*9)|"*3
"|$x|"  Try it online! # Charcoal, 12 bytes ←×⁵_↑⁴ ×⁵_‖Ｏ  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. ‖Ｏ  Reflect to complete the square. # Canvas, 9 bytes Ｉ×⁹-x~‰‟│  Try it here! Compression. Less boring 12-byte answer: ２|＊５_×＋⇵ ∔↕╪ 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, 2422 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 '18 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 '18 at 8:28 • @KevinCruijssen Fixed and golfed off a byte – Okx Nov 29 '18 at 8:36 • My biggest problem with the new 05AB1E is that the debug feature is terrible – Okx Nov 29 '18 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 '18 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╴？Ｂ<‟│


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 '18 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 '18 at 8:58
• @KevinCruijssen whoops! Thanks for spotting that! – Henry T Nov 29 '18 at 9:00
• 50 bytes if you move around the newlines: print' '+'_'*9+('\n|'+' '*9+'|')*4+'\n|'+'_'*9+'|' – Okx Nov 29 '18 at 9:36
• 48 bytes: print' '+'_'*9+'\n| |'*5+'\n|_________|', 9 spaces between | and | – Vedant Kandoi Nov 29 '18 at 9:51
• @Okx ahh good spot! – Henry T Nov 29 '18 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:

# 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|").

# 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 '18 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 '18 at 14:35
• ok, thank you for the explanation! – isaace Nov 29 '18 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 '18 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

_=> _
| |
| |
| |


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


# Red, 53 bytes

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


Try it online!

# Java, 59 Bytes

v-> " _______\n|       |\n|       |\n|       |\n|_______|"

• Should this be embedded in a function or something? – Jo King Nov 29 '18 at 16:04

# Brain-Flak, 317 bytes

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


Try it online!

Not golfy at all, just a test.

## Turing Machine But Way Worse - 3251 bytes

0 0 0 1 1 0 0
0 1 0 1 2 0 0
0 2 1 0 3 1 0
0 3 1 0 4 0 0
0 4 0 1 0 0 0
1 0 1 1 1 0 0
1 1 0 0 2 0 0
1 2 1 1 5 0 0
0 5 0 1 6 0 0
0 6 1 0 7 0 0
0 7 0 1 3 0 0
1 3 1 1 8 0 0
0 8 1 0 4 0 0
1 4 1 1 5 0 0
1 5 1 1 9 0 0
0 9 1 0 6 0 0
1 6 1 1 7 0 0
1 7 1 1 10 0 0
0 10 1 1 11 0 0
0 11 1 0 8 1 0
1 8 1 0 9 1 0
1 9 1 0 10 1 0
1 10 1 0 11 1 0
1 11 1 1 12 1 0
1 12 1 0 13 1 0
1 13 1 1 14 1 0
1 14 1 0 15 1 0
1 15 1 1 16 1 0
1 16 1 1 17 0 0
1 17 0 1 18 0 0
1 18 1 1 19 0 0
1 19 0 0 20 0 0
1 20 1 0 12 0 0
0 12 0 0 21 0 0
1 21 1 0 22 0 0
1 22 0 0 13 0 0
0 13 0 0 23 0 0
1 23 0 0 14 1 0
0 14 0 1 15 0 0
0 15 1 0 16 0 0
0 16 0 1 24 0 0
1 24 1 1 17 0 0
0 17 1 0 25 0 0
1 25 1 1 26 0 0
1 26 1 1 18 0 0
0 18 1 0 27 0 0
1 27 1 1 28 0 0
1 28 1 1 29 0 0
1 29 1 1 19 0 0
0 19 1 1 30 0 0
1 30 0 0 31 1 0
1 31 0 0 32 0 0
1 32 0 0 33 0 0
1 33 0 0 34 0 0
1 34 1 0 35 0 0
1 35 0 0 20 1 0
0 20 0 1 21 1 0
0 21 0 1 36 1 0
1 36 1 1 22 1 0
0 22 0 1 23 1 0
0 23 0 0 24 1 0
0 24 0 1 25 1 0
0 25 0 0 26 1 0
0 26 0 1 27 1 0
0 27 1 1 28 0 0
0 28 1 0 37 0 0
1 37 1 0 29 0 0
0 29 1 0 38 0 0
1 38 1 0 30 0 0
0 30 1 0 31 1 0
0 31 0 1 39 0 0
1 39 0 0 32 0 0
0 32 0 1 33 0 0
0 33 0 1 40 0 0
1 40 0 0 34 0 0
0 34 0 1 35 0 0
0 35 0 1 41 0 0
1 41 0 0 36 0 0
0 36 0 1 37 0 0
0 37 0 1 42 0 0
1 42 1 1 43 0 0
1 43 0 1 38 0 0
0 38 1 0 39 1 0
0 39 1 1 44 0 0
1 44 0 0 45 0 0
1 45 1 0 46 0 0
1 46 1 0 40 0 0
0 40 1 0 41 0 0
0 41 1 0 42 0 0
0 42 1 0 43 1 0
0 43 0 1 47 0 0
1 47 0 0 44 0 0
0 44 0 1 45 0 0
0 45 0 1 48 0 0
1 48 1 1 49 0 0
1 49 0 0 50 0 0
1 50 1 1 46 0 0
0 46 0 1 51 0 0
1 51 0 1 52 0 0
1 52 0 0 47 1 0
0 47 0 0 48 1 0
0 48 0 1 49 1 0
0 49 0 0 50 1 0
0 50 0 1 51 1 0
0 51 0 0 52 1 0
0 52 0 1 53 1 0
0 53 0 0 54 1 0
0 54 0 1 55 1 0
0 55 1 1 56 0 0
0 56 1 0 53 0 0
1 53 1 0 57 0 0
0 57 1 0 54 0 0
1 54 1 0 58 0 0
0 58 1 0 59 1 0
0 59 0 1 55 0 0
1 55 0 0 60 0 0
0 60 0 1 61 0 0
0 61 0 1 56 0 0
1 56 0 0 62 0 0
0 62 0 1 63 0 0
0 63 0 1 57 0 0
1 57 0 0 64 0 0
0 64 0 1 65 0 0
0 65 0 1 58 0 0
1 58 1 1 59 0 0
1 59 0 1 66 0 0
0 66 1 0 67 1 0
0 67 1 1 60 0 0
1 60 0 0 61 0 0
1 61 1 0 62 0 0
1 62 1 0 68 0 0
0 68 1 0 69 0 0
0 69 1 0 70 0 0
0 70 1 0 71 1 0
0 71 0 1 63 0 0
1 63 0 0 72 0 0
0 72 0 1 73 0 0
0 73 0 1 64 0 0
1 64 1 1 65 0 0
1 65 0 0 66 0 0
1 66 1 1 74 0 0
0 74 0 1 67 0 0
1 67 0 1 68 0 0
1 68 0 0 75 1 0
0 75 0 0 76 1 0
0 76 0 1 77 1 0
0 77 0 0 78 1 0
0 78 0 1 79 1 0
0 79 0 0 80 1 0
0 80 0 1 81 1 0
0 81 0 0 82 1 0
0 82 0 1 83 1 0
0 83 1 1 84 0 0
0 84 1 0 69 0 0
1 69 1 0 85 0 0
0 85 1 0 70 0 0
1 70 1 0 86 0 0
0 86 1 0 87 1 0
0 87 0 1 71 0 0
1 71 0 0 88 0 0
0 88 0 1 89 0 0
0 89 0 1 72 0 0
1 72 0 0 90 0 0
0 90 0 1 91 0 0
0 91 0 1 73 0 0
1 73 0 0 92 0 0
0 92 0 1 93 0 0
0 93 0 1 74 0 0
1 74 1 1 75 0 0
1 75 0 1 94 0 0
0 94 1 0 95 1 0
0 95 1 1 76 0 0
1 76 0 0 77 0 0
1 77 1 0 78 0 0
1 78 1 0 96 0 0
0 96 1 0 97 0 0
0 97 1 0 98 0 0
0 98 1 0 99 1 0
0 99 0 1 79 0 0
1 79 1 1 80 0 0
1 80 0 0 81 0 0
1 81 1 1 100 0 0
0 100 0 1 82 0 0
1 82 1 1 83 0 0
1 83 1 1 84 0 0
1 84 1 1 101 0 0
0 101 1 1 102 0 0
0 102 1 0 85 1 0
1 85 1 0 86 1 0
1 86 1 0 87 1 0
1 87 1 0 88 1 0
1 88 1 1 89 1 0
1 89 1 0 90 1 0
1 90 1 1 91 1 0
1 91 1 0 92 1 0
1 92 1 1 93 1 0
1 93 1 1 94 0 0
1 94 1 1 95 0 0
1 95 0 1 96 0 0
1 96 0 0 103 0 0
0 103 0 0 97 0 0
1 97 1 0 98 0 0
1 98 1 0 99 0 0
1 99 1 0 104 0 0
0 104 1 0 100 1 1


Made with the help of ASCII_only's program generator.

# R, 55 bytes

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


Try it online!

# BrainFuck, 129 bytes

+++>++++++++[>++++>>>>+<<<<<-]>[>+++>++++>+<<<-]>->---->>++<.<<.........>>>.<<<<<<[>>>>.>.........<.>>.<<<<<<-]>>>>.<.........>.


This was my first code golf post so it isn't that optimized.

iisiisddddc{dd}ddsdddddccccccccc{ddddddddd}ddsicisiiic{{d}dd}iisddddccccccccc{dd}dsiiic{{d}dd}dsicisiiic{{d}dd}iisddddccccccccc{dd}dsiiic{{d}dd}dsicisiiic{{d}dd}iisddddccccccccc{dd}dsiiic{{d}dd}dsicisiiic{ddd}icccccccccd{iii}c