# Generate a box based on user input [duplicate]

NOTE: This question is different than Draw an ASCII Rectangle because the user has to input only 1 number to generate a box, unlike the other question, where the user has to input the x and y size of the box.

Your task is to create a box based upon user input. Let's say I inputted 2. The box generated would look like:

--
--


As in, two by two long. Or, if I entered 7:

-------
|     |
|     |
|     |
|     |
|     |
-------


So, seven by seven.

Notice the box generated above has 5 bars up and seven hyphens across. The hyphen directly above or below the bars does count as one vertical iteration.

One more example. I enter 5. The box generated:

-----
|   |
|   |
|   |
-----


You can use any programming language you wish. The task is to be able to generate a box using the least possible amount of bytes.

[1] dzaima in SOGL, 17 bytes

[2] Adam in APL, 27 bytes

[3] HyperNeutrino in Python, 51 bytes

## marked as duplicate by DJMcMayhem♦ code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jul 4 '17 at 16:26

• @DJMcMayhem While I don't dispute your dupeuammer, this challenge is slightly different and offers some golfing opportunities because the characters are unique across rows, not columns, which is how most languages work. I trust your judgement more than mine though :P – HyperNeutrino Jul 4 '17 at 16:32
• Can we assume that the input will always be at least 2? – dzaima Jul 4 '17 at 16:35
• Your comment about the input consisting of only one number isn't a valid de-duplicating reason. If the other one requires both dimensions and this only requires one, then every solution there can be easily transferred to this question by simply repeating the left argument and using that as the right argument. See my above point though. – HyperNeutrino Jul 5 '17 at 19:56

# SOGL V0.12, 21 17 bytes

1.⁰{1.┐∙ž}:┐┌ŗH╬8


Try it Here!

Explanation:

1.⁰                push 1, input and wrap in an array
{     }         for each item in that array do
1                push 1
.┐∙             get an array of input amount of items of "|"
ž            at coordinates [currentArrayItem; 1] place those bars
:        duplicate it
┐┌ŗ     replace "|" with "-"
H    rotate anti-clockwise
╬8  place the 2nd array over the 1st


# JavaScript (ES6), 61 60 bytes

n=>${h="-"[r="repeat"](n)}${|\${" "[r](n-=2)}|
[r](n)}+h


# APL (Dyalog), 27 bytes

'-'⍪'-'⍪⍨'|','|',⍨''⍴⍨2⍴-∘2


Try it online!

-∘2 subtract two

2⍴reshape into length 2

''⍴⍨ use that as height and width to reshape an empty string (padding with spaces)

'|',⍨ put stiles on the right

'|', put stiles on the left

'-'⍪⍨ put dashes below

'-'⍪ put dashes on top

• {'--| '[a⌊⌽⊖a←2⊥¨×⍳⌽⍵]} – ngn Jul 7 '17 at 8:51
• @ngn I don't get it. Can you post a TryAPL or TIO link? – Adám Jul 7 '17 at 10:46
• it's []io=0 tio.run/##SyzI0U2pTMzJT///qG9qZv6jtgkG/… – ngn Jul 7 '17 at 13:44
• @n It almost answers this then, alhough you can specify input in reverse, and use ⎕, saving 3 bytes. However, here there is only one input, so we need '--| '[a⌊⌽⊖a←2⊥¨×⍳2/⎕] – Adám Jul 7 '17 at 13:47
• I must have confused the two... well, still an improvement. – ngn Jul 7 '17 at 15:08

# Python, 51 bytes

lambda x:'-'*x+'\n'+('|'+' '*(x-2)+'|\n')*(x-2)+'-'*x


I tested this on my laptop and then manually wrote this answer on mobile so please tell me if this doesn't work.

• I believe you meant *x at the end. – Fedone Jul 6 '17 at 9:36
• @Fedone Yes, that is what I meant. Thanks. – HyperNeutrino Jul 6 '17 at 17:59