20
\$\begingroup\$

Challenge

Given an integer n (where 4<=n<=10**6) as input create an ASCII art "prison door"* measuring n-1 characters wide and n characters high, using the symbols from the example below.


Example

╔╦╗
╠╬╣
╠╬╣
╚╩╝

The characters used are as follows:

┌───────────────┬─────────┬───────┐
│ Position      │ Symbol  │ Char  │
├───────────────┼─────────┼───────┤
│ Top Left      │    ╔    │ 9556  │
├───────────────┼─────────┼───────┤
│ Top           │    ╦    │ 9574  │
├───────────────┼─────────┼───────┤
│ Top Right     │    ╗    │ 9559  │
├───────────────┼─────────┼───────┤
│ Right         │    ╣    │ 9571  │
├───────────────┼─────────┼───────┤
│ Bottom Right  │    ╝    │ 9565  │
├───────────────┼─────────┼───────┤
│ Bottom        │    ╩    │ 9577  │
├───────────────┼─────────┼───────┤
│ Bottom Left   │    ╚    │ 9562  │
├───────────────┼─────────┼───────┤
│ Left          │    ╠    │ 9568  │
├───────────────┼─────────┼───────┤
│ Inner         │    ╬    │ 9580  │
└───────────────┴─────────┴───────┘

Rules

  • You may take input by any reasonable, convenient means as long as it's permitted by standard I/O rules.
  • For the purposes of this challenge, in languages where the symbols used to build the "door" are multi-byte characters, they may be counted towards your score as a single byte each.
  • All other characters (single- or multi-byte) should be counted as normal.
  • Output may not contain any trailing spaces but a trailing newline is permitted if absolutely necessary.
  • This is so lowest byte count wins.

Test Cases

Input: 4
Output:
╔╦╗
╠╬╣
╠╬╣
╚╩╝

Input: 8
Output:
╔╦╦╦╦╦╗
╠╬╬╬╬╬╣
╠╬╬╬╬╬╣
╠╬╬╬╬╬╣
╠╬╬╬╬╬╣
╠╬╬╬╬╬╣
╠╬╬╬╬╬╣
╚╩╩╩╩╩╝

Input: 20
Output:
╔╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╗
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣
╚╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╝

* Yes, I'm aware that the bigger it gets the less it looks like a prison door! :D

\$\endgroup\$
12
  • 4
    \$\begingroup\$ This would have been good if you could input both x and y dimensions \$\endgroup\$
    – Beta Decay
    Commented Jun 15, 2017 at 13:19
  • 18
    \$\begingroup\$ It was in the Sandbox more than long enough for you to suggest that. \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 13:21
  • \$\begingroup\$ Can my program contain even trough isn't in its codepage? If not, then is "'Z“ζ permitted as one byte cost (or 2)? (push 9580, convert to unicode)? \$\endgroup\$
    – dzaima
    Commented Jun 15, 2017 at 13:43
  • \$\begingroup\$ @dzaima For the purposes of this challenge, in languages where the symbols used for the "door" take multiple bytes, they may be counted towards your score as a single byte each. \$\endgroup\$
    – Okx
    Commented Jun 15, 2017 at 13:46
  • 1
    \$\begingroup\$ How about allowing FT7, E#3, LWJ? The prison door might look a little weird; but that would resolve all codepage and counting issues. \$\endgroup\$
    – Titus
    Commented Mar 14, 2018 at 16:51

30 Answers 30

10
\$\begingroup\$

Java 11, 156 151 148 118 89 bytes

n->"╔"+"╦".repeat(n-=3)+"╗\n"+("╠"+"╬".repeat(n)+"╣\n").repeat(n+1)+"╚"+"╩".repeat(n)+"╝"

Try it online.

Old 118 bytes answer in Java 8:

n->{String a="╔",b="╠",c="╚";for(int i=n;i-->3;a+="╦",b+="╬")c+="╩";a+="╗\n";for(b+="╣\n";n-->2;)a+=b;return a+c+"╝";}

-30 bytes by creating a port of @raznagul C# (.NET Core) answer, after I golfed 5 bytes.

Try it here.

Explanation:

n->                    // Method with integer parameter and String return-type
  "╔"                  //  The top-left corner
  +"╦"                 //  Appended with the top edge
      .repeat(n-=3)    //  Repeated input-3 times (-2 for the corners, -1 for width)
  +"╗\n"               //  Appended with the top-right corner and a newline
  +("╠"                //   The left edge
    +"╬"               //   Appended with the middle part
        .repeat(n)     //   Repeated input-3 times (-2 for edges, -1 for width)
    +"╣\n"             //   Appended with the right edge and a newline
          ).repeat(n+1)//  And repeat this entire line n-2 times (-2 for first/last rows)
  +"╚"                 //  Appended with the bottom-left corner
  +"╩"                 //  Appended with the bottom edge
      .repeat(n)       //  Repeated input-3 times
  +"╝"                 //  Appended with the bottom-right corners
\$\endgroup\$
5
  • \$\begingroup\$ Can you save any bytes with escape/char codes instead of hardcoding them? \$\endgroup\$ Commented Jun 15, 2017 at 14:23
  • \$\begingroup\$ @TheLethalCoder Perhaps, but since the challenge rule state we can count the symbols as 1 byte each, it's probably shorter like this (hence the 156 byte-count instead of the actual 176). But feel free to try some things to make it shorter with the char-codes. \$\endgroup\$ Commented Jun 15, 2017 at 14:30
  • \$\begingroup\$ Ah I missed that part of the rules. \$\endgroup\$ Commented Jun 15, 2017 at 14:31
  • 2
    \$\begingroup\$ +1 for the goes to (-->) operator. \$\endgroup\$
    – raznagul
    Commented Jun 16, 2017 at 11:56
  • 1
    \$\begingroup\$ If you use i-->3, i-->2 and j-->3´ you can save 5 bytes by removing the n-=3` and n+1. \$\endgroup\$
    – raznagul
    Commented Jun 16, 2017 at 11:57
8
\$\begingroup\$

Charcoal, 34 - 5 = 29 bytes

A⁻N³γUB╬↓×╠γ╠¶╚×╩γ‖BOγ‖BO↑⁺γ

Try it online! Link is to verbose version of code. 5 byte reduction is for box drawing characters.

ReflectOverlapOverlap(0) should be equivalent to ReflectMirror() but instead Charcoal just does a ReflectTransform() instead, otherwise this solution would also work for n=3. Here's a workaround which shows what would happen for n=3 for 38 - 5 = 33 bytes:

A⁻N³γUB╬↓×╠γ╠¶╚×╩γ¿γ‖BOγ‖M‖BO↑⁺γ¹

Better still, if ReflectOverlapOverlap(0) worked, but I didn't bother supporting n=3, then I could do this for 31 - 4 = 27 bytes:

A⁻N³γUB╬↓×╠γ╚×╩γ‖BOγ‖BO↑⁻γ¹
\$\endgroup\$
9
  • 1
    \$\begingroup\$ Hmm, didn't knew Charcoal also reflects/mirrors to and such. "Charcoal's byte-counter isn't working for some reason." Maybe Charcoal's byte-counter isn't working because those characters aren't part of its code-page? You can count them as 1 byte each according to the challenge rules though, so this is indeed 27. \$\endgroup\$ Commented Jun 16, 2017 at 7:09
  • \$\begingroup\$ @KevinCruijssen It depends on which operator you use. (I have to go back and double-check each time; there are a number of them and it gets confusing...) \$\endgroup\$
    – Neil
    Commented Jun 16, 2017 at 7:41
  • \$\begingroup\$ @Neil Oops, that's a bug, will fix ASAP. Thanks for finding it! \$\endgroup\$
    – ASCII-only
    Commented Jun 17, 2017 at 5:12
  • \$\begingroup\$ @Neil Also for some reason it's broken when n=4 \$\endgroup\$
    – ASCII-only
    Commented Jun 17, 2017 at 6:10
  • 1
    \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$
    – ASCII-only
    Commented Jun 17, 2017 at 11:14
6
\$\begingroup\$

Charcoal, 44 42 bytes

Crossed out 44 is still regular 44

A⁺±³NαA⁺¹αω╔×α╦¦╗J⁰¦¹×ω╠
¦╚×α╩¦╝M↖↑×ω╣M↙¤╬

Try it online!

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

Haskell, 75 bytes

w i(a:b:c)=a:(b<$[4..i])++c
f n=concat$w(n+1)$w n<$>["╔╦╗\n","╠╬╣\n","╚╩╝"]  

Try it online!

Function w takes an integer i and a list where a is the first, b the second element and c the rest of the list and makes a new list a, followed by i-3 copies of b, followed by c. Apply w first on each each element of the list ["╔╦╗\n","╠╬╣\n","╚╩╝"] and then again (with i increased by 1) on the resulting list. Concatenate into a single list.

\$\endgroup\$
2
  • \$\begingroup\$ What is the <$ operator? Is it just >> with the arguments flipped? \$\endgroup\$ Commented Jun 16, 2017 at 13:03
  • \$\begingroup\$ @AneeshDurg: <$ is originally from Data.Functor and has been put into Prelude. It's almost the same as >>. a <$ b replaces every element in b with a, whereas b >> a expects a to be a list and concatenates length of b copies of a. [1,2] >> "aa" -> "aaaa", "aa" <$ [1,2] -> ["aa","aa"]. Note: 'x' <$ [1,2] equals [1,2] >> "x". \$\endgroup\$
    – nimi
    Commented Jun 16, 2017 at 14:12
5
\$\begingroup\$

Vim, 29 bytes

3<C-x>C╔╦╗
╠╬╣
╚╩╝<Esc>h<C-v>kkx@-Pjyy@-p

Since there are control characters, here's an xxd dump:

00000000: 3318 43e2 9594 e295 a6e2 9597 0de2 95a0  3.C.............
00000010: e295 ace2 95a3 0de2 959a e295 a9e2 959d  ................
00000020: 1b68 166b 6b78 402d 506a 7979 402d 70    .h.kkx@-Pjyy@-p

Try it online! (The V interpreter seems to have issues with exotic characters, so that link uses more mundane ones.)

Explanation

3<C-x>     " Decrement the number by 3
C╔╦╗
╠╬╣
╚╩╝<Esc>   " Cut the number (goes in @- register) and enter the "template"
h<C-v>kkx  " Move to the middle column, highlight and cut it
@-P        " Paste @- copies of the cut column
jyy        " Move to the middle line and copy it
@-p        " Paste @- copies of the copied line
\$\endgroup\$
2
  • \$\begingroup\$ To confirm: Is it only the TIO interpreter that's choking on the symbols? \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 22:25
  • \$\begingroup\$ @Shaggy Yeah, it throws a Python error about Latin-1, not a Vim error. (I used the V page just because TIO doesn't have a plain Vim page, and I think V uses Latin-1.) Vim on my machine doesn't have any issue with the characters. \$\endgroup\$
    – Jordan
    Commented Jun 15, 2017 at 23:49
5
\$\begingroup\$

GNU sed, 74 + 1 = 75 bytes

+1 byte for -r flag. Takes input as a unary number.

s/1111(1*)/╔╦\1╗\n;\1╠╬\1╣\n╚╩\1╝/
:
s/(.)1/\1\1/
t
s/;([^;\n]+)/\1\n\1/
t

Try it online!

Explanation

This is pretty simple. Suppose the input is 6 (unary 111111). The first line drops four 1s and transforms the remaining input into this:

╔╦11╗
;11╠╬11╣
╚╩11╝

The third line, in a loop, replaces every 1 with the character preceding it. This creates our columns:

╔╦╦1╗
;11╠╬11╣
╚╩11╝

╔╦╦╦╗
;11╠╬11╣
╚╩11╝

...

╔╦╦╦╗
;;;╠╬╬╬╣
╚╩╩╩╝

Notice that this has also duplicated the ; character. Finally, the fifth line, in a loop, replaces every ; character with a copy of the line that follows:

╔╦╦╦╗
;;╠╬╬╬╣
╠╬╬╬╣
╚╩╩╩╝

╔╦╦╦╗
;╠╬╬╬╣
╠╬╬╬╣
╠╬╬╬╣
╚╩╩╩╝

╔╦╦╦╗
╠╬╬╬╣
╠╬╬╬╣
╠╬╬╬╣
╠╬╬╬╣
╚╩╩╩╝
\$\endgroup\$
4
\$\begingroup\$

Jelly, 33 bytes

...is it 33? - it costs 5 to convert from one byte string literals (code page indexes) to the Unicode characters.

_2µ“€ðБẋ“¡Ø¤“©ßµ‘js3x€2¦€’+⁽"7ỌY

A full program printing the result.

Try it online!

How?

_2µ“€ðБẋ“¡Ø¤“©ßµ‘js3x€2¦€’+⁽"7ỌY - Main link: n
_2                                - subtract 2
  µ                               - start a new monadic chain with n-2 on the left
   “€ðБ                          - code page indexes [12, 24, 15] (middle row characters)
        ẋ                         - repeat n-2 times (make unexpanded middle rows)
         “¡Ø¤“©ßµ‘                - code page indexes [[0,18,3],[6,21,9]] (top & bottom)
                  j               - join (one list: top + middles + bottom)
                   s3             - split into threes (separate into the unexpanded rows)
                          ’       - decrement n-2 = n-3
                        ¦€        - sparsely apply to €ach:
                       2          -   at index 2
                     x€           -   repeat €ach (expand centre of every row to n-3 chars)
                            ⁽"7   - literal 9556
                           +      - addition (0->9556; 12->9568; etc...)
                               Ọ  - cast to characters (╠; ╔; etc...)
                                Y - join with newlines
                                  - implicit print
\$\endgroup\$
2
  • \$\begingroup\$ @Shaggy - I am using 9 bytes to represent the characters inside string literals - these are code page indexes. The 5 bytes before the Y at the end, +⁽"7Ọ, adds 9556 to these and then casts to characters. Are they (the 5) free? I feel like that would be the same as if I could use the Unicode characters directly. (I could also use actual characters rather than code page indexes and use a mapping for more bytes). \$\endgroup\$ Commented Jun 15, 2017 at 14:27
  • 1
    \$\begingroup\$ Nope. After discussion, it was concluded that only the char itself can always be counted as 1, not any other representation. \$\endgroup\$ Commented Jun 15, 2017 at 14:30
4
\$\begingroup\$

Rockstar, 150 104 bytes

Listen to B
let B be-3
X's-1
say "╔"+"╦"*B+"╗"
While B-X
say "╠"+"╬"*B+"╣"
let X be+1

say "╚"+"╩"*B+"╝"

Copy Paste it here!

-46 bytes from Shaggy.

I was inspired by Shaggy from this comment.

Here's the real rock song (sort of).

Listen to the bars
Knock the bars down, down, down
Let the end be the bars
Build the end up
Shout "╔"+"╦"*the bars+"╗"
While the end ain't nothing
say "╠"+"╬"*the bars+"╣"
Knock the end down

Shout "╚"+"╩"*the bars+"╝"
Let the prison be gone
\$\endgroup\$
4
  • \$\begingroup\$ The characters for the door can be counted as 1 byte each, so this is 150 bytes. You can golf it down to 104, though. \$\endgroup\$
    – Shaggy
    Commented Sep 24, 2020 at 11:02
  • \$\begingroup\$ I think you posted the wrong link, cause that looks like the original program. \$\endgroup\$
    – Razetime
    Commented Sep 24, 2020 at 11:04
  • \$\begingroup\$ That was quick! I fixed it almost straight away. Try again ;) \$\endgroup\$
    – Shaggy
    Commented Sep 24, 2020 at 11:06
  • \$\begingroup\$ gotcha, now it works. \$\endgroup\$
    – Razetime
    Commented Sep 24, 2020 at 11:08
3
\$\begingroup\$

Python 3, 75 bytes

n=int(input())-3
print("╔"+"╦"*n+"╗\n"+("╠"+"╬"*n+"╣\n")*-~n+"╚"+"╩"*n+"╝")

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ You can golf it slightly by starting at n-3: n=int(input())-3;print("╔"+"╦"*n+"╗\n"+("╠"+"╬"*n+"╣\n")*(n+1)+"╚"+"��"*n+"╝") \$\endgroup\$ Commented Jun 15, 2017 at 14:03
  • \$\begingroup\$ Also, n+1 is equivalent to -~n. \$\endgroup\$
    – Leaky Nun
    Commented Jun 15, 2017 at 14:08
3
\$\begingroup\$

Dyalog APL, 71 bytes

{('╔',('╠'⍴⍨⍵-2),'╚'),((⍵-3)\⍪('╦',('╬'⍴⍨⍵-2),'╩')),'╗',('╣'⍴⍨⍵-2),'╝'}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ You can definitely golf this. E.g. You can always replace (some expr)f Y with Y f⍨ some expr. \$\endgroup\$
    – Adám
    Commented Jun 15, 2017 at 15:28
  • \$\begingroup\$ @Adám I know, it's in progress, I'm not on computer currently \$\endgroup\$
    – Uriel
    Commented Jun 15, 2017 at 15:41
3
\$\begingroup\$

Japt, 60 52 49 48 36 bytes

"╔{Uµ3 ç'╦}╗{UÄ ç"
╠{ç'╬}╣"}
╚{ç'╩}╝

Try it online!

Another version (47 bytes + -R flag)

"8{Uµ3 ç'J};{UÄ ç"D{ç'P}G"}>{ç'M}A"c_+9500ÃòU+2

Needs the -R flag (added to the input field). Try it online!

How does it work?

Because I originally assumed the 'door-characters' cost more than one byte, I figured I could save quite a few bytes by encoding them. Then, I subtracted 9500 from the character codes, which left me with the characters 8J; DPG >MA, which only cost one byte each. Then, I could just add 9500 to each character code, and all would be well.

 "8{   Uµ 3 ç'J}  ;{   UÄ  ç"D{   ç'P}  G"}  >{   ç'M}  A"c_+9500Ã òU+2
 "8"+((U-=3 ç'J)+";"+((U+1 ç"D"+(Uç'P)+"G")+">"+(Uç'M)+"A"c_+9500} òU+2
 "8"+           +";"+                      +">"+      +"A"              # Take this string of characters
     ((U-=3 ç'J)                                                        # Repeat "J" input - 3 times
                     ((    ç              )                             # Repeat the string
                            "D"+(Uç'P)+"G"                              # "D" + input-3 times "P" + "G"
                       U+1                                              # Input - 2 times
                                                (Uç'M)                  # Repeat "M" input - 3 times
                                                          c_     }      # Take the character code of every character
                                                            +9500       # Add 9500 to it
                                                          c_     }      # And convert it back to a character
                                                                   òU+2 # Split this string on every (input)th character
                                                                        # Print the resulting array, joined with newlines.
\$\endgroup\$
2
  • \$\begingroup\$ Oh, yeah, you're right. \$\endgroup\$
    – Luke
    Commented Jun 15, 2017 at 14:12
  • \$\begingroup\$ 32 bytes \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 15:03
3
\$\begingroup\$

Ruby, 54 52 bytes

-2 bytes thanks to ymbirtt.

->n{?╔+?╦*(n-=3)+"╗
"+(?╠+?╬*n+"╣
")*-~n+?╚+?╩*n+?╝}

Try it online!

Ungolfed

This is super boring:

->n{
   ?╔ + ?╦ * (n-=3) + "╗\n" + 
  (?╠ + ?╬ * n      + "╣\n") * -~n + 
   ?╚ + ?╩ * n      + ?╝
}
\$\endgroup\$
1
  • \$\begingroup\$ You can shorten the (n+1) a little by writing -~n - operator precedence will save you the brackets, too. \$\endgroup\$
    – ymbirtt
    Commented Jun 16, 2017 at 10:09
3
\$\begingroup\$

Java 8, 102 + 101 bytes

java.util.function.BiFunction<String,Integer,String>r=(c,n)->"".valueOf(new char[n]).replace("\0",c);

n->{n-=3;return "╔"+r.apply("╦",n)+"╗\n"+r.apply('╠'+r.apply("╬",n)+"╣\n",-~n)+"╚"+r.apply("╩",n)+"╝";}

This is another string repeater of the same length:

java.util.function.BiFunction<String,Integer,String>r=(c,n)->{String p=c;for(;--n>0;p+=c);return p;}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Not bad, you can make your approach even lower than my answer. First of all you can lower it to 78 + 72 bytes (150 in total) by using a Java 7 method instead of the BiFunction: n->{n-=3;return"╔"+r("╦",n)+"╗\n"+r("╠"+r("╬",n)+"╣\n",-~n)+"╚"+r("╩",n)+"╝";} and String r(String c,int n){return c.valueOf(new char[n]).replace("\0",c);} Try it online. And the second method can also be changed to String r(String c,int n){String r=c;for(;n-->1;r+=c);return r;} (63 bytes), so it becomes 141 bytes in total \$\endgroup\$ Commented Mar 14, 2018 at 15:59
  • \$\begingroup\$ Correction, you can even lower it to 130 bytes: n->"╔"+r("╦",n-=3)+"╗\n"+r("╠"+r("╬",n)+"╣\n",-~n)+"╚"+r("╩",n)+"╝" and String r(String c,int n){String r=c;for(;n-->1;r+=c);return r;} Try it online. \$\endgroup\$ Commented Mar 14, 2018 at 16:01
3
\$\begingroup\$

C# (.NET Core), Score 123 (141 bytes) Score 118 (136 bytes)

n=>{string a="╔",b="╠",c="╚";for(int i=3;i++<n;a+="╦",b+="╬")c+="╩";a+="╗\n";for(b+="╣\n";n-->2;)a+=b;return a+c+"╝";}

Try it online!

-5 bytes thanks to @KevinCruijssen

Explanation:

n => 
{
    string a = "╔", b = "╠", c = "╚"; //Initialize the first, last and the middle lines with the starting character.
    for (int i = 3; i++ < n;          //Loop n-3 times
        a += "╦", b += "╬")           //Add the middle character to the first and middle line.
        c += "╩";                     //Add the middle character to the last line.
    a += "╗\n";                       //Add the end character to the first line.
    for (b += "╣\n";                  //Add the end character to the first line.
        n-- > 2;)                     //Loop n-2 times.
        a += b;                       //Add the middle line to the first line.
    return a + c + "╝";               //Add the last line and the final character and return.
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice answer, +1 from me. I know it's been a while, but you can golf 5 more bytes by changing b+="╣\n";c+="╝";for(;n-->2;)a+=b;return a+c;}; to for(b+="╣\n";n-->2;)a+=b;return a+c+"╝";} Try it online. \$\endgroup\$ Commented Mar 14, 2018 at 16:11
  • \$\begingroup\$ @KevinCruijssen: Thank you. \$\endgroup\$
    – raznagul
    Commented Mar 14, 2018 at 16:44
3
\$\begingroup\$

Stax, 23 bytes

÷ÅoB↔╒╢Fm|╦a⌐á5µ┐»♫÷d���Ñ

Run and debug it

Here's the ungolfed version. Amusingly, it's actually smaller for stax not to use the literal characters because including them as a literal would prevent source packing.

"2Pfj_EQGG]T"!  packed representation of the 9 characters
3/              split into groups of 3
GG              call into trailing program twice
m               print each row
}               trailing program begins here
1|xv\           [1, --x - 1]; x starts as original input
:B              repeat each element corresponding number of times
                effectively, this repeats the internal row of the matrix
M               transpose door; this way it expands the two dimensions

Run this one

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

05AB1E, 29 bytes

3-…╩╬╦S×`…╔ÿ╗Š…╠ÿ╣IÍ×s…╚ÿ╝Jä»

Try it online!

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

Swift, 161 bytes

let f:(String,Int)->String={String(repeating:$0,count:$1)};var p={i in print("╔\(f("╦",i-3))╗\n\(f("╠\(f("╬",i-3))╣\n",i-2))╚\(f("╩",i-3))╝")}

Un-golfed:

let f:(String,Int)->String = {
    String(repeating:$0,count:$1)
}
var p={ i in
    print("╔\(f("╦",i-3))╗\n\(f("╠\(f("╬",i-3))╣\n",i-2))╚\(f("╩",i-3))╝")
}

You can try this answer out here

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

QBIC, 78 bytes

[:-3|X=X+@╦`]?@╔`+X+@╗`[b-2|Y=Z[b-3|Y=Y+@╬`]?@╠`+Y+@╣`}[b-3|W=W+@╩`]?@╚`+W+@╝`

Fortunately, all of the symbols used in out cell door are on the QBasic codepage.

Explanation

            The TOP
[:-3|       FOR a = 1 to n-3 (-1 for the width, -2 for beginning and end)
X=X+@╦`]    Build out X$ with the parts of the middle-top
?@╔`+X+@╗`  Then print that preceded and followed by the corners
┘           Syntactic linebreak
            
            The MIDDLE
[b-2|       FOR c = 1 to n-2 (all the middle rows)
Y=Z         Reset Y$ to ""
            Build up the middle rows in the same way as the top,
            just with different symbols and once for each middle row
[b-3|Y=Y+@╬`]?@╠`+Y+@╣`
}           Close the FOR loop
            The BOTTOM
            The same as the top, just with different symbols
[b-3|W=W+@╩`]?@╚`+W+@╝`

Sample Output

Command line: 7

╔╦╦╦╦╗
╠╬╬╬╬╣
╠╬╬╬╬╣
╠╬╬╬╬╣
╠╬╬╬╬╣
╠╬╬╬╬╣
╚╩╩╩╩╝
\$\endgroup\$
5
  • 1
    \$\begingroup\$ +1 for using a language that actually has them as one byte chars in its default code page. \$\endgroup\$
    – Joshua
    Commented Jun 16, 2017 at 7:23
  • \$\begingroup\$ Can you add a TIO (or equivalent)? \$\endgroup\$
    – Shaggy
    Commented Jun 16, 2017 at 8:29
  • \$\begingroup\$ @Shaggy codegolf.stackexchange.com/questions/125237/… \$\endgroup\$
    – steenbergh
    Commented Jun 16, 2017 at 8:32
  • 1
    \$\begingroup\$ Oh, yeah! I'll remember that eventually, I promise! :D \$\endgroup\$
    – Shaggy
    Commented Jun 16, 2017 at 8:37
  • \$\begingroup\$ @Shaggy well, don't get too used to the idea. I just found a working Emscripten-build of Dosbox running QBasic. I'll try to gear that toward QBIC in the coming month, so a web env might yet arrive... \$\endgroup\$
    – steenbergh
    Commented Jun 16, 2017 at 8:46
2
\$\begingroup\$

PHP, 131 bytes, 113 chars

for($z=str_split("╔╠╚╦╬╩╗╣╝",3);$i<$a=$argn;)echo str_pad($z[$b=$i++?$i<$a?1:2:0],3*$a-3,$z[$b+3]),$z[$b+6],"\n";

Try it online!

PHP, 133 bytes, 115 chars

for(;$i<$a=$argn;)echo str_pad(["╔","╠","╚"][$b=$i++?$i<$a?1:2:0],3*$a-3,["╦","╬","╩"][$b]),["╗","╣","╝"][$b],"\n";

Try it online!

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

JavaScript (ES6), 86 bytes

This is significantly longer than the other JS answer, but I wanted to give it a try with an alternate method.

n=>(g=i=>--i?`╬╣╠╩╝╚╦╗╔
`[(j=i%n)?!--j+2*!(n-j-2)+3*(i<n)+6*(i>n*n-n):9]+g(i):'')(n*n)

How?

We assign a weight to each edge of the grid: 1 for right, 2 for left, 3 for bottom and 6 for top. The sum of the weights gives the index of the character to use.

8666667    0 1 2 3 4 5 6 7 8
2000001    ╬ ╣ ╠ ╩ ╝ ╚ ╦ ╗ ╔
2000001
2000001
2000001
2000001
2000001
5333334

Demo

let f =

n=>(g=i=>--i?`╬╣╠╩╝╚╦╗╔
`[(j=i%n)?!--j+2*!(n-j-2)+3*(i<n)+6*(i>n*n-n):9]+g(i):'')(n*n)

console.log(f(8))

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

JavaScript (ES6), 80 74 bytes

n=>`╔${"╦"[a="repeat"](n-=3)}╗${`
╠${"╬"[a](n)}╣`[a](n+1)}
╚${"╩"[a](n)}╝`
\$\endgroup\$
8
  • \$\begingroup\$ You can count the symbols as one byte each, making this 80 bytes. And you should be able to make better use of template literals to save a few bytes ;) \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 13:52
  • \$\begingroup\$ You can only count the symbols as one byte if you can find an ES6 implementation that will take CP437 input natively. \$\endgroup\$ Commented Jun 15, 2017 at 13:56
  • \$\begingroup\$ @user5090812, It's an allowance specific to this challenge. \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 13:58
  • \$\begingroup\$ @user5090812 No need to find that implementation, because the challenge rules state "For the purposes of this challenge, in languages where the symbols used for the "door" take multiple bytes, they may be counted towards your score as a single byte each." So this has a byte-count of 80 bytes instead of 98 (if I counted correctly). \$\endgroup\$ Commented Jun 15, 2017 at 13:58
  • \$\begingroup\$ Well, that's a bad rule. It removes all the incentive to look for a better way to store the characters. \$\endgroup\$
    – Luke
    Commented Jun 15, 2017 at 14:08
2
\$\begingroup\$

Batch, 126 bytes

@set s=
@for /l %%i in (4,1,%1)do @call set s=%%s%%Î
@echo É%s:Î=Ë%»
@for /l %%i in (3,1,%1)do @echo Ì%s%¹
@echo È%s:Î=Ê%¼

Works in CP437 or CP850. Looks like this in those code pages:

@set s=
@for /l %%i in (4,1,%1)do @call set s=%%s%%╬
@echo ╔%s:╬=╦%╗
@for /l %%i in (3,1,%1)do @echo ╠%s%╣
@echo ╚%s:╬=╩%╝
\$\endgroup\$
2
\$\begingroup\$

Retina, 56 50 bytes

.+
$*╬╣
^╬╬╬
╠
.?
$_¶
T`╠╬╣`╔╦╗`^.*
T`╠╬╣`╚╩╝`.*¶$

Try it online! Works by building up a square of ╬s and then fixing up the edges (in particular three colums are deleted when the sides are added).

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

PowerShell, 67 bytes

'╔'+'╦'*($x=$args[0]-3)+'╗';,('╠'+'╬'*$x+'╣')*($x+1);'╚'+'╩'*$x+'╝'

Takes input $args[0], subtracts 3, saves that into $x, uses that in the construction of the top of the door to output the appropriate number of middle sections. Then we're outputting the middle rows, of which we have $x+1 of. Finally, the bottom row is similar to the top row. All of those are left on the pipeline, and the implicit Write-Output inserts a newline between elements for free.

Try it online!

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

Perl 5, 61

60 characters of code (90 including the multibyte door characters) + 1 for -p

$_='╔'.'╦'x($n=$_-3)."╗\n";$_.=y/╔╦╗/╠╬╣/r x++$n.y/╔╦╗/╚╩╝/r

Try it online!

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

C# (.NET Core), 130 bytes

n=>"╔"+R("╦",n-=3)+"╗\n"+R("╠"+R("╬",n)+"╣\n",-~n)+"╚"+R("╩",n)+"╝";string R(string c,int n){string r=c;for(;n-->1;r+=c);return r;}

Port of @RobertoGraham's Java 8 answer, after I golfed about 70 bytes.

Try it online.

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

MAWP, 73 bytes

@=MM"╔":!3-["╦":1-]`"╗
":2-["╠":M3-["╬":1-]`"╣
":1-]`"╚":M3-["╩":1-]`"╝":

Try it!

Note the strings with newlines

\$\endgroup\$
5
  • \$\begingroup\$ MAWP 1.1 would be insane with thes glyphs lmao \$\endgroup\$
    – Razetime
    Commented Sep 24, 2020 at 7:17
  • \$\begingroup\$ @Razetime yeah. Probably would make a script to brute-force the constants for me lol \$\endgroup\$
    – Dion
    Commented Sep 24, 2020 at 7:18
  • \$\begingroup\$ Your output is too tall, it should be one line less. \$\endgroup\$
    – Shaggy
    Commented Sep 24, 2020 at 11:05
  • 1
    \$\begingroup\$ @Shaggy should be fixed now \$\endgroup\$
    – Dion
    Commented Sep 25, 2020 at 5:56
  • 1
    \$\begingroup\$ @Shaggy actually the width was too big also, fixed that as well \$\endgroup\$
    – Dion
    Commented Sep 25, 2020 at 6:02
1
\$\begingroup\$

Mathematica, 106 bytes

(T[a_,b_,c_]:=a<>Table[b,#-3]<>c;w=Column;w[{T["╔","╦","╗"],w@Table[T["╠","╬","╣"],#-2],T["╚","╩","╝"]}])&
\$\endgroup\$
4
  • \$\begingroup\$ Could you add a TIO (or equivalent)? \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 14:02
  • 1
    \$\begingroup\$ goto sandbox.open.wolframcloud.com/app/objects paste the code(ctrl+v), add [8] at the end and press shift+enter \$\endgroup\$
    – ZaMoC
    Commented Jun 15, 2017 at 14:06
  • \$\begingroup\$ There appears to be an extra line break between each line, would I be right in saying that's a problem with the rendering of the outpu, rather than the output itself? \$\endgroup\$
    – Shaggy
    Commented Jun 15, 2017 at 14:28
  • \$\begingroup\$ @Shaggy wolfram cloud displays all characters in a funny-distorted way so it is not the best way to present such tasks.there are no extra lines and everything looks ok on mathematica. copy and paste your test case to check.I did and they look identical \$\endgroup\$
    – ZaMoC
    Commented Jun 15, 2017 at 14:32
1
\$\begingroup\$

oK, 38 chars

`0:"╔╠╚╦╬╩╗╣╝"{+x+/:3*0,2_x}@&1,|1,-2+

Try it online.

k does not seem to want to handle unicode well, so I went with oK.

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

J, 41 37 bytes

ucp@'╬╠╣╦╔╗╩╚╝'{~1 1|.{.&6 3+/<:{.2,*

Try it online!

Default box drawing takes 13 bytes, unfortunately the best way of replacing the characters I could find costs 28.

\$\endgroup\$
0

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