In The Jailhouse Now

18

4

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

Shaggy

Posted 2017-06-15T13:13:42.600

Reputation: 24 623

4This would have been good if you could input both x and y dimensions – Beta Decay – 2017-06-15T13:19:03.753

15It was in the Sandbox more than long enough for you to suggest that. – Shaggy – 2017-06-15T13:21:36.920

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)? – dzaima – 2017-06-15T13:43:42.737

@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. – Okx – 2017-06-15T13:46:17.057

@Okx - not represetable in any byte amount, "'Z“ζ equaling one byte would be like in javascript "╬" costing 1 byte – dzaima – 2017-06-15T13:49:24.217

@dzaima, unless an overwhelming case is made otherwise, the allowance applies only to those characters used in the challenge. – Shaggy – 2017-06-15T13:54:25.593

@Shaggy so to compete I need to count the representation of the characters as 5 bytes each? – dzaima – 2017-06-15T14:09:29.423

I wish the height and width didn't differ by an odd number... – Neil – 2017-06-15T16:41:22.813

@Downvoter: feedback would be appreciated. – Shaggy – 2017-06-15T22:22:26.403

@Shaggy "unless an overwhelming case is made otherwise, the allowance applies only to those characters used in the challenge" So to clarify, the string of +s representing in Brainfuck would count as 9,580 bytes, not 1? :-) – Ray – 2017-06-16T01:33:40.730

How about allowing FT7, E#3, LWJ? The prison door might look a little weird; but that would resolve all codepage and counting issues. – Titus – 2018-03-14T16:51:31.370

Answers

9

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

Kevin Cruijssen

Posted 2017-06-15T13:13:42.600

Reputation: 67 575

Can you save any bytes with escape/char codes instead of hardcoding them? – TheLethalCoder – 2017-06-15T14:23:05.580

@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. – Kevin Cruijssen – 2017-06-15T14:30:18.637

Ah I missed that part of the rules. – TheLethalCoder – 2017-06-15T14:31:52.927

2+1 for the goes to (-->) operator. – raznagul – 2017-06-16T11:56:41.053

1If you use i-->3, i-->2 and j-->3´ you can save 5 bytes by removing then-=3andn+1`. – raznagul – 2017-06-16T11:57:52.130

7

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↑⁻γ¹

Neil

Posted 2017-06-15T13:13:42.600

Reputation: 95 035

1Hmm, 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. – Kevin Cruijssen – 2017-06-16T07:09:50.040

@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...) – Neil – 2017-06-16T07:41:29.523

@Neil Oops, that's a bug, will fix ASAP. Thanks for finding it! – ASCII-only – 2017-06-17T05:12:15.347

@Neil Also for some reason it's broken when n=4 – ASCII-only – 2017-06-17T06:10:50.007

@ASCII-only So what's the command to reflect without axis overlap, transforming characters, and keeping the original? – Neil – 2017-06-17T10:52:51.153

That would be ReflectMirror if I'm understanding you correctly – ASCII-only – 2017-06-17T10:54:31.490

@Neil Oh oops, they don't work with overlap = 0, sorry will fix asap – ASCII-only – 2017-06-17T10:59:33.910

@ASCII-only Ah, so ReflectMirror() works, but ReflectMirror(:Right) gives the same results as Reflect(:Right)... – Neil – 2017-06-17T11:09:41.567

1

Let us continue this discussion in chat.

– ASCII-only – 2017-06-17T11:14:40.530

6

Charcoal, 44 42 bytes

Crossed out 44 is still regular 44

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

Try it online!

Okx

Posted 2017-06-15T13:13:42.600

Reputation: 15 025

Let us continue this discussion in chat.

– Erik the Outgolfer – 2017-06-15T13:51:18.770

6

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.

nimi

Posted 2017-06-15T13:13:42.600

Reputation: 34 639

What is the <$ operator? Is it just >> with the arguments flipped? – Aneesh Durg – 2017-06-16T13:03:16.797

@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". – nimi – 2017-06-16T14:12:49.373

5

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:

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

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

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

Jordan

Posted 2017-06-15T13:13:42.600

Reputation: 5 001

5

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

Jordan

Posted 2017-06-15T13:13:42.600

Reputation: 5 001

To confirm: Is it only the TIO interpreter that's choking on the symbols? – Shaggy – 2017-06-15T22:25:53.023

@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. – Jordan – 2017-06-15T23:49:12.767

4

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

Jonathan Allan

Posted 2017-06-15T13:13:42.600

Reputation: 67 804

@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). – Jonathan Allan – 2017-06-15T14:27:27.923

Nope. After discussion, it was concluded that only the char itself can always be counted as 1, not any other representation. – Erik the Outgolfer – 2017-06-15T14:30:58.183

3

Python 3, 75 bytes

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

Try it online!

Leaky Nun

Posted 2017-06-15T13:13:42.600

Reputation: 45 011

You can golf it slightly by starting at n-3: n=int(input())-3;print("╔"+"╦"*n+"╗\n"+("╠"+"╬"*n+"╣\n")*(n+1)+"╚"+"╩"*n+"╝") – Kevin Cruijssen – 2017-06-15T14:03:06.537

Also, n+1 is equivalent to -~n. – Leaky Nun – 2017-06-15T14:08:42.807

3

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.

Luke

Posted 2017-06-15T13:13:42.600

Reputation: 4 675

Oh, yeah, you're right. – Luke – 2017-06-15T14:12:22.007

32 bytes – Shaggy – 2017-06-15T15:03:55.343

3

Dyalog APL, 71 bytes

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

Try it online!

Uriel

Posted 2017-06-15T13:13:42.600

Reputation: 11 708

You can definitely golf this. E.g. You can always replace (some expr)f Y with Y f⍨ some expr. – Adám – 2017-06-15T15:28:56.947

@Adám I know, it's in progress, I'm not on computer currently – Uriel – 2017-06-15T15:41:12.950

2

JavaScript (ES6), 80 74 bytes

n=>`╔${"╦"[a="repeat"](n-=3)}╗${`
╠${"╬"[a](n)}╣`[a](n+1)}
╚${"╩"[a](n)}╝`

Luke

Posted 2017-06-15T13:13:42.600

Reputation: 4 675

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 ;) – Shaggy – 2017-06-15T13:52:58.970

You can only count the symbols as one byte if you can find an ES6 implementation that will take CP437 input natively. – user5090812 – 2017-06-15T13:56:52.880

@user5090812, It's an allowance specific to this challenge. – Shaggy – 2017-06-15T13:58:04.823

@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). – Kevin Cruijssen – 2017-06-15T13:58:11.303

Well, that's a bad rule. It removes all the incentive to look for a better way to store the characters. – Luke – 2017-06-15T14:08:12.207

For me, the userscript counts 75 chars in your code. – ETHproductions – 2017-06-15T15:58:19.993

@ETHproductions, it looks like Luke forgot to update the byte count with his last edit. There are a few stray & missing characters, though; the count is actually 74. n=>'╔${"╦"[a="repeat"](n-=3)}╗${'\n╠${"╬"[a](n)}╣'[a](n+1)}\n╚${"╩"[a](n)}╝' (replace 's with backticks and \ns with literal newlines. – Shaggy – 2017-06-15T16:47:08.577

@Shaggy: Besides the special rule, I possess the required environment. – Joshua – 2017-06-16T07:21:51.380

2

05AB1E, 29 bytes

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

Try it online!

Emigna

Posted 2017-06-15T13:13:42.600

Reputation: 50 798

2

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

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

steenbergh

Posted 2017-06-15T13:13:42.600

Reputation: 7 772

1+1 for using a language that actually has them as one byte chars in its default code page. – Joshua – 2017-06-16T07:23:36.630

Can you add a TIO (or equivalent)? – Shaggy – 2017-06-16T08:29:28.633

1Oh, yeah! I'll remember that eventually, I promise! :D – Shaggy – 2017-06-16T08:37:23.443

@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... – steenbergh – 2017-06-16T08:46:21.793

2

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

Caleb Kleveter

Posted 2017-06-15T13:13:42.600

Reputation: 647

2

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!

Jörg Hülsermann

Posted 2017-06-15T13:13:42.600

Reputation: 13 026

2

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      + ?╝
}

Jordan

Posted 2017-06-15T13:13:42.600

Reputation: 5 001

You can shorten the (n+1) a little by writing -~n - operator precedence will save you the brackets, too. – ymbirtt – 2017-06-16T10:09:34.540

2

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))

Arnauld

Posted 2017-06-15T13:13:42.600

Reputation: 111 334

2

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

raznagul

Posted 2017-06-15T13:13:42.600

Reputation: 424

1

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.

– Kevin Cruijssen – 2018-03-14T16:11:43.683

@KevinCruijssen: Thank you. – raznagul – 2018-03-14T16:44:28.973

2

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!

Roberto Graham

Posted 2017-06-15T13:13:42.600

Reputation: 1 305

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

– Kevin Cruijssen – 2018-03-14T15:59:25.983

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.

– Kevin Cruijssen – 2018-03-14T16:01:17.433

2

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

recursive

Posted 2017-06-15T13:13:42.600

Reputation: 8 616

1

Mathematica, 106 bytes

(T[a_,b_,c_]:=a<>Table[b,#-3]<>c;w=Column;w[{T["╔","╦","╗"],w@Table[T["╠","╬","╣"],#-2],T["╚","╩","╝"]}])&

J42161217

Posted 2017-06-15T13:13:42.600

Reputation: 15 931

Could you add a TIO (or equivalent)? – Shaggy – 2017-06-15T14:02:52.447

1

goto https://sandbox.open.wolframcloud.com/app/objects/ paste the code(ctrl+v), add [8] at the end and press shift+enter

– J42161217 – 2017-06-15T14:06:53.553

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? – Shaggy – 2017-06-15T14:28:09.990

@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 – J42161217 – 2017-06-15T14:32:18.340

1

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.

zgrep

Posted 2017-06-15T13:13:42.600

Reputation: 1 291

1

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

Neil

Posted 2017-06-15T13:13:42.600

Reputation: 95 035

1

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:╬=╩%╝

Neil

Posted 2017-06-15T13:13:42.600

Reputation: 95 035

1

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!

AdmBorkBork

Posted 2017-06-15T13:13:42.600

Reputation: 41 581

1

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!

Xcali

Posted 2017-06-15T13:13:42.600

Reputation: 7 671

1

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.

Kevin Cruijssen

Posted 2017-06-15T13:13:42.600

Reputation: 67 575

1

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.

FrownyFrog

Posted 2017-06-15T13:13:42.600

Reputation: 3 112