17
\$\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\$
  • 3
    \$\begingroup\$ This would have been good if you could input both x and y dimensions \$\endgroup\$ – Beta Decay Jun 15 '17 at 13:19
  • 15
    \$\begingroup\$ It was in the Sandbox more than long enough for you to suggest that. \$\endgroup\$ – Shaggy Jun 15 '17 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 Jun 15 '17 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 Jun 15 '17 at 13:46
  • \$\begingroup\$ @Okx ` ╬` - not represetable in any byte amount, "'Z“ζ equaling one byte would be like in javascript "╬" costing 1 byte \$\endgroup\$ – dzaima Jun 15 '17 at 13:49

28 Answers 28

9
\$\begingroup\$

Java 8, 156 151 148 118 bytes

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 online.

Old 148 byte answer:

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

-5 bytes thanks to @raznagul.

Explanation:

Try it here.

n->{                   // Method with integer parameter and String return-type
  String r="╔";        //  Result String (starting with the top-left corner)
  int i=n,j;           //  Indexes `i` and `j`
  for(;i-->3;          //  Loop (1) `n`-3 times:
      r+="╦"           //   Append result with top edges
  );                   //  End of loop (1)
  r+="╗\n╠";           //  Append result with the top-right corner, new-line and left edge
  for(i=n;i-->2        //  Loop (2) `n`-2 times
      ;                //     After every iteration:
      r+="╣\n"         //   Append result with right edge and new-line
      +(i>2?"╠":"╚"))  //    + either the left edge or bottom-left corner
    for(j=n;j-->3;     //   Inner loop (3) `n`-3 times:
        r+="╬"         //    Append result with middle section
    );                 //   End of inner loop (3)
                       //  End of loop (2) (implicit / single-line body)
  for(;n-->3;          //  Loop (4) `n`-3 times:
    r+="╩"             //   Append result with bottom edges
  );                   //  End of loop (4)
  return r+"╝";        //  Return result with its bottom-right corner
}                      // End of method
\$\endgroup\$
  • \$\begingroup\$ Can you save any bytes with escape/char codes instead of hardcoding them? \$\endgroup\$ – TheLethalCoder Jun 15 '17 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\$ – Kevin Cruijssen Jun 15 '17 at 14:30
  • \$\begingroup\$ Ah I missed that part of the rules. \$\endgroup\$ – TheLethalCoder Jun 15 '17 at 14:31
  • 2
    \$\begingroup\$ +1 for the goes to (-->) operator. \$\endgroup\$ – raznagul Jun 16 '17 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 Jun 16 '17 at 11:57
7
\$\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\$
  • 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\$ – Kevin Cruijssen Jun 16 '17 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 Jun 16 '17 at 7:41
  • \$\begingroup\$ @Neil Oops, that's a bug, will fix ASAP. Thanks for finding it! \$\endgroup\$ – ASCII-only Jun 17 '17 at 5:12
  • \$\begingroup\$ @Neil Also for some reason it's broken when n=4 \$\endgroup\$ – ASCII-only Jun 17 '17 at 6:10
  • 1
    \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – ASCII-only Jun 17 '17 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\$
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\$
  • \$\begingroup\$ What is the <$ operator? Is it just >> with the arguments flipped? \$\endgroup\$ – Aneesh Durg Jun 16 '17 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 Jun 16 '17 at 14:12
6
\$\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\$
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\$
  • \$\begingroup\$ To confirm: Is it only the TIO interpreter that's choking on the symbols? \$\endgroup\$ – Shaggy Jun 15 '17 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 Jun 15 '17 at 23:49
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\$
  • \$\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\$ – Jonathan Allan Jun 15 '17 at 14:27
  • \$\begingroup\$ Nope. After discussion, it was concluded that only the char itself can always be counted as 1, not any other representation. \$\endgroup\$ – Erik the Outgolfer Jun 15 '17 at 14:30
3
\$\begingroup\$

Python 3, 75 bytes

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

Try it online!

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

Dyalog APL, 71 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ You can definitely golf this. E.g. You can always replace (some expr)f Y with Y f⍨ some expr. \$\endgroup\$ – Adám Jun 15 '17 at 15:28
  • \$\begingroup\$ @Adám I know, it's in progress, I'm not on computer currently \$\endgroup\$ – Uriel Jun 15 '17 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\$
  • \$\begingroup\$ Oh, yeah, you're right. \$\endgroup\$ – Luke Jun 15 '17 at 14:12
  • \$\begingroup\$ 32 bytes \$\endgroup\$ – Shaggy Jun 15 '17 at 15:03
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\$
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\$
  • 1
    \$\begingroup\$ +1 for using a language that actually has them as one byte chars in its default code page. \$\endgroup\$ – Joshua Jun 16 '17 at 7:23
  • \$\begingroup\$ Can you add a TIO (or equivalent)? \$\endgroup\$ – Shaggy Jun 16 '17 at 8:29
  • \$\begingroup\$ @Shaggy codegolf.stackexchange.com/questions/125237/… \$\endgroup\$ – steenbergh Jun 16 '17 at 8:32
  • 1
    \$\begingroup\$ Oh, yeah! I'll remember that eventually, I promise! :D \$\endgroup\$ – Shaggy Jun 16 '17 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 Jun 16 '17 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\$
  • \$\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 Jun 15 '17 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\$ – user5090812 Jun 15 '17 at 13:56
  • \$\begingroup\$ @user5090812, It's an allowance specific to this challenge. \$\endgroup\$ – Shaggy Jun 15 '17 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\$ – Kevin Cruijssen Jun 15 '17 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 Jun 15 '17 at 14:08
2
\$\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\$
  • \$\begingroup\$ You can shorten the (n+1) a little by writing -~n - operator precedence will save you the brackets, too. \$\endgroup\$ – ymbirtt Jun 16 '17 at 10:09
2
\$\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\$
  • \$\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\$ – Kevin Cruijssen Mar 14 '18 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\$ – Kevin Cruijssen Mar 14 '18 at 16:01
2
\$\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\$
  • 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\$ – Kevin Cruijssen Mar 14 '18 at 16:11
  • \$\begingroup\$ @KevinCruijssen: Thank you. \$\endgroup\$ – raznagul Mar 14 '18 at 16:44
2
\$\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\$
1
\$\begingroup\$

Mathematica, 106 bytes

(T[a_,b_,c_]:=a<>Table[b,#-3]<>c;w=Column;w[{T["╔","╦","╗"],w@Table[T["╠","╬","╣"],#-2],T["╚","╩","╝"]}])&
\$\endgroup\$
  • \$\begingroup\$ Could you add a TIO (or equivalent)? \$\endgroup\$ – Shaggy Jun 15 '17 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\$ – J42161217 Jun 15 '17 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 Jun 15 '17 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\$ – J42161217 Jun 15 '17 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\$

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\$
1
\$\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\$
1
\$\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\$
1
\$\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\$
1
\$\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\$
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\$

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.