You want to send an ASCII letter to someone, but you need an envelope to put it in. Your task is to output an envelope given a size as input.


  • Given positive integer input i, your envelope will be i characters tall (not counting the top row), and i*2 characters wide (not counting the side columns). In other words, your envelope will be i+1 characters tall and (i*2)+2 characters wide.
  • Output must be in the form of text, using \, /, _, |, and .
  • The flap of the envelope must be on the row above the bottom row of the envelope unless impossible (as with an envelope of size 1).
  • Trailing whitespace is allowed.

Example input and output:



|\    /|
| \__/ |

|\      /|
| \    / |
|  \__/  |

This is a challenge, so shortest code wins!


9 Answers 9


05AB1E, 41 bytes


Try it online or verify the first few outputs.


i              # If the (implicit) input is 1:
 '|„|\‚       '#  Push pair of strings ["_","|\"]
ë              # Else:
 2Êi           #  If the (implicit) input is NOT 2:
    ÍF         #   Loop `N` in the range [0,input-2):
      ðI×      #    Push a string with the input amount of spaces
         '\Nǝ '#    Insert a "\" character at index `N`
     }         #   Close the loop
   }           #  Close the inner if-statement
„\_            #  Push string "\_"
   Ij          #  Pad leading spaces until the string is of a length equal to the input
     ¤         #  Push the last character (without popping): "_"
      I×       #  Repeat it the input amount of times as string
        ©      #  Store it in variable `®` (without popping)
)              #  Wrap all values on the stack into a list
 '|ì          '#  Prepend a "|" in front of each string
    ®š         #  Prepend string `®` to the list
}              # Close the outer if-else statement
 º             # Mirror each inner string
  .c           # Join by newlines and centralize
               # (adding a single leading space to the first "_"-string)
               # (after which the result is output implicitly)
  • 13
    \$\begingroup\$ Congrats on reaching 100k! \$\endgroup\$
    – ophact
    Commented Mar 24, 2022 at 16:09

Python 3, 207 181 180 177 146 130 bytes

lambda i,u="__",b=" ":b+u*i+"".join(f"\n|{b*x}\{(b*(i*2+~x*2),u)[x==i-2]}/{b*x}|"for x in range(i-1))+("\n|\/|",f"\n|{u*i}|")[i>1]

Try it online!

To 181 bytes: Golfed the code even more thanks to @Kevin Cruijssen.

To 180 bytes: -1 bytes thanks again to @Kevin Cruijssen, by replacing the i!=1 with i<2.

To 177 bytes: Moved the whole "nonsense soup" line onto the same line as the for loop, thanks to @des54321's suggestion.

To 146 bytes: Some major byte-saving golfs thanks to @ElPedro.

To 130 bytes: More golfs by @Kevin Cruijssen, including replacing \\ with \.

  • 1
    \$\begingroup\$ 181 bytes with some golfs :) The u,b declaration is a single line to save a byte; the if/else are both single lines with and/or to save byes; and the (i*2)-(x*2)-2 (for which you don't need the parenthesis) is i*2+~x*2 to save some bytes (~x is -x-1 btw). \$\endgroup\$ Commented Mar 24, 2022 at 22:20
  • 1
    \$\begingroup\$ One more small golf for -1: s+(i!=1and f"|{u*i*2}|"or"|\\/|") can be s+(i<2and"|\\/|"or f"|{u*i*2}|") \$\endgroup\$ Commented Mar 25, 2022 at 7:40
  • 2
    \$\begingroup\$ After @ElPedro golfs everything can be put onto a single line and you can use a lambda for 134 bytes. \$\endgroup\$ Commented Mar 29, 2022 at 14:29
  • 2
    \$\begingroup\$ 130 bytes by replacing both \\ with \ (apparently they don't have to be escaped in Python's strings depending on the character behind it). \$\endgroup\$ Commented Mar 29, 2022 at 14:33
  • 2
    \$\begingroup\$ @KevinCruijssen - I guessed you'd be back! Thanks for finishing it off for me. Was busy this afternoon :) Didn't know that about the \\ in f-strings. Learned something new today. Thanks. \$\endgroup\$
    – ElPedro
    Commented Mar 29, 2022 at 15:23

Vyxal C, 49 bytes


Try it Online!

  • \$\begingroup\$ Doesn't work, draws backslashes instead of slashes \$\endgroup\$
    – allxy
    Commented Apr 30, 2022 at 22:43
  • \$\begingroup\$ @allxy Fixed and shavead off a couple more bytes. \$\endgroup\$
    – naffetS
    Commented May 1, 2022 at 0:44

Charcoal, 28 bytes


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


Input i.


Draw half of the bottom row of _s.


Draw the left column of |s.


Draw the top row of _s.


If i is not 1, then...


... draw the i-1 \s on the left and one of the two middle _s, ...


... otherwise overwrite the bottom _ with a \.


Reflect to complete the envelope.


Javascript, 181 177 174 Bytes

Code is split into newlines for readability, see link for 174 byte string.

o=' '+b;
for(e=0;e<n-1;e++)y=r(' ',e),o+=z+y+'\\'+r(e!=n-2?' ':'_',n*2-2*(e+1))+'/'+y+'|';
return o;}

Try me online.

  • Saved 4 bytes pulling \n| into a variable z
  • Saved 3 bytes pulling r(' ',e) into y every loop

I'm not too happy with my performance here, especially the implicit check I had to do to get the i=1 output working, but oh well.

  • \$\begingroup\$ Just so you know, readability doesn't matter in this case, so you can make it as unreadable as you like ;-)! The goal is to have it as golfed as possible. \$\endgroup\$ Commented Apr 23, 2022 at 23:58

Vyxal o, 37 bytes


Try it Online!

\_*                                   # <input> copies of _
   :£                                 # Duplicate and set gregister
     ðpm,                             # Prepend a space and print mirrored
         ċ[                     |‛|\m # If it's 1, print `|\/|`, else:
           ɽ‹                         # 0...n-1
             \\꘍                      # For each, prepend that many spaces to an underscore
                ṫ   J                 # To the last...
                 \_+                  # Append an underscore
                     ↲                # Pad all of that to length n
                      ¥J              # Append the underscores that we stored in the register earlier
                        \|vp          # Prepend a | to each
                            vøṀ⁋      # Mirror and print

Python 3.8 (pre-release), 107 bytes

lambda n:[' '+(a:="__"*n)]+['|%s|'%[a," "*i+f'\{"_ "[i<n-2]*2*(n+~i)}/'+" "*i][i<n-(n>2)]for i in range(n)]

Try it online!

-20 by @emanresuA

  • \$\begingroup\$ You can save a bunch by outputting as a list of lines, which opens up a whole host of golfing oppurtunities - 107 bytes. \$\endgroup\$
    – emanresu A
    Commented May 1, 2022 at 10:04

Perl 5 + -M5.10.0 -a, 98 bytes

say$".__ x$_,map{'
|',/@F/*($#a=$_-1)?__ x$_.'|':"@a\\".($_<"@F"-1?'  ':__)x("@F"-$_)."/@a|"}1..$_

Try it online!

Currently on mobile (in a rainy field!) so I'll add an explanation later!


05AB1E, 68 bytes


Try it online!


ð              Push space
'_Iи           Push I underscores (I = input)
JJÂJ           Push reverse of that
UX,            Put that in X and print it
I<F            Loop from 1 to N-1 (N = index)
  '|           Push '|' (pipe)
  ðNи          Push N spaces
  '\           Push '\' (backslash)
  N>I<Qi'_     If N+1 == I-1, push _ (underscore)
    ëð}        Otherwise push space
  IN-<·и       Pop and repeat that by (I-N-1)*2
  '/           Push '/' (slash)
  ðNи          Push N spaces
  '|           Push '|' (pipe)
  JJ,          Join and print
I2‹i"|\/|"     If I == 1, push '|\/|'
  ëXð'|:}      Otherwise, push X with spaces replaced with pipes
,              Print

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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