Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

In The Jailhouse Now

+7
−0

Challenge

Given an integer n>=4 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.
  • 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.
  • You may output an array/list of lines instead of a multi-line string.
  • Output may not contain any leading or trailing whitespace other than a trailing newline where absolutely necessary.
  • This is code-golf 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

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General (1 comment)

6 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+2
−0

C (gcc), 119 118 116 115 bytes

#define p(x,y,z) printf(i^1?i^c?#z:#y:#x)
i,j;f(c){for(i=1;i<=c;p(╗\n,╝\n,╣\n),i++)for(j=p(╔,╚,╠);j++<c;)p(╦,╩,╬);}

Try it online!

Function solution.

I started with a recursive solution but it didn't work out well... though I'm still convinced that this can be shaved down quite a bit with recursion.

EDIT:

Recursive version which currently landed at exactly 115 bytes too...

#define p(x,y,z) printf(i^1?i^c?#z:#x:#y);
c,j;f(i){for(c=c?c:i,j=p(╔,╚,╠)j++<c;)p(╦,╩,╬)p(╗\n,╝\n,╣\n)--i?f(i):0;}
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General (2 comments)
+2
−0

Scala, 90 89 88 bytes

Saved 2 bytes thanks to Shaggy

n=>1 to n map{x=>val s=if(x<2)"╔╦╗"else if(x<n)"╠╬╣"else"╚╩╝";s(0)+(""+s(1))*(n-3)+s(2)}

Try it in Scastie!

I feel like there's a nicer way to repeat middle elements of a list n times, but this is all I can golf it for now.

n => //The input
1 to n //Make a range [1..n]
map{x=> //For each x in that range, make a line:
val s= //s is a string in the form "$left$inner$right"
 if(x<2)"╔╦╗" //For the top
 else if(x<n)"╠╬╣" //For the inner parts
 else"╚╩╝"; //For the bottom
s(0)+(""+s(1))*(n-3)+s(2)} //Repeat the inner part n-3 times
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

You can remove the space after the last `else` to save a byte. (4 comments)
+2
−0

Python 3, 74 bytes

lambda n:"╔"+"╦"*(n-3)+"╗\n"+("╠"+"╬"*(n-3)+"╣\n")*(n-2)+"╚"+"╩"*(n-3)+"╝"

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Sclipting, (UTF-16) 80 bytes

갰減먩놔 먩놦①復먩놗겮꺕똀 먩놬①復①增疊먩놣겮꺕똀會먩놣겮꺕떠 먩놩⑴復먩놝

Explanation

Input n pushed on stack
갰減        Subtract 3
먩놔        "╔"
먩놦        "╦"
①復         String of above repeated n-3 times
먩놗겮꺕똀   "╗\n╠"

먩놬        "╬"
①復         String of above repeated n-3 times
①增疊       List of above repeated (n-3)+1 times
먩놣겮꺕똀   "╣\n╠"
會          Join the list with separater above

먩놣겮꺕떠   "╣\n╚"
먩놩        "╩"
⑴復        String of above repeated n-3 times (but finally remove n-3 from stack)
먩놝        "╝"
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Ruby, 53 bytes

->n{n-=3;[?╔+?╦*n+?╗,*[?╠+?╬*n+?╣]*(n+1),?╚+?╩*n+?╝]}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

[51 bytes](https://tio.run/##KypNqvyfZvtf1y6vOk/X1tg62v7R1CnaQGKZVh6Imq6jBRJaAGKvgQgtjtXSrcvTAbJmgbgr... (1 comment)
+0
−0

C (clang), 210 198 183 bytes

i,j,k,l;s(v,w,x,y,z){printf("%s",v);for(;w<x;w++){printf("%s",y);}puts(z);}main(){scanf("%i",&i);l=i-3;s("╔",j,l,"╦","╗");for(j=0;j<i-2;j++){s("╠",k,l,"╬","╣");}s("╚",j=0,l,"╩","╝");}

Try it online!

Still wondering if these characters could even count as a byte, probably two. ¯\_(ツ)_/¯

A special golfing trick I learned. If you don't want to repeat the loops, then make a function. For some reason, C (clang) is okay with such non-returning function that's not main(). Enough abuse for this.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »