[Question]
  [
(Based on [this closed challenge](https://codegolf.stackexchange.com/questions/229794/drawing-a-grid-using-and-in-python-using-the-least-bytes-possible#229794), [related](https://codegolf.stackexchange.com/questions/58243/16-bit-binary-grid))
Given an integer n > 1, draw a grid composed of the characters: "-" "+" and "|". However, since I want the grid to look nice, the horizontal component should be 2 wide.
Trailing spaces for each line are not required.
#### Examples:
n = 2
```
  | 
--+--
  | 
```
n = 3
```
  |  | 
--+--+--
  |  | 
--+--+--
  |  |
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins!
  
[Answer]
# [Python 3](https://docs.python.org/3/), 49 bytes
```
lambda n:f'\n{"--+"*~-n}--\n'.join(['  |'*~-n]*n)
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKk09Jq9aSVdXW0mrTjevVlc3Jk9dLys/M08jWl1BoUYdJBqrlaf5Py2/SCFTITNPoSgxLz1Vw0hHwUzTikuhoCgzr0QjTSNTUxPG0fwPAA "Python 3 – Try It Online")
[Answer]
# Python 3, ~~70 62 60~~ 58 bytes
```
lambda n:f"-{'-+-'*~-n}-\n".join([f" {' | '*~-n} \n"]*n)
```
Thanks to @Underslash, @Jonathan Allan for removing 4 bytes.
[Answer]
# JavaScript (ES6), ~~67~~ 66 bytes
Recursive.
```
f=(n,k=n*2*(n*=3)-n)=>k--?` -|+
`[k%n?~-k%n%3&2|k/n&1:4]+f(n,k):''
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zVYjTyfbNk/LSEsjT8vWWFM3T9PWLltX1z5BQbdGmyshOls1z75OF0iqGqsZ1WTr56kZWpnEaqeB9Glaqav/T87PK87PSdXLyU/XSNMw0tTkQhUxxhAx0dT8DwA "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), ~~61~~ 58 bytes
*Saved 3 bytes thanks to @EliteDaMyth*
The straightforward way.
```
n=>`${s='  |'[R='repeat'](--n)}
${'--+'[R](n)}--
`[R](n)+s
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i5BpbrYVl1BoUY9OshWvSi1IDWxRD1WQ1c3T7OWS6VaXVdXGygTqwHk6upyJUCY2sX/k/PzivNzUvVy8tM10jSMNDW5kEVQeWkaxgTkTTQ1/wMA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
ＵＯ⊖×³Ｎ⊖⊗θ  |¶--+
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98/KSc/L13DJTW5KDU3Na8kNUUjJDM3tVjDWEfBM6@gtMSvNDcptUhDU1NTRwFZlUt@aVIOkC4ESSgpKNTE5OnqaitpWv//b/xftywHAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
ＵＯ
```
Draw a rectangle...
```
⊖×³Ｎ
```
... width `3n-1`...
```
⊖⊗θ
```
... height `2n-1`...
```
  |¶--+
```
... filled with  `|` and `--+` on alternate lines.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `rj`, 15 bytes
```
`+--|  `½*ẋfḢvḢ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=rj&code=%60%2B--%7C%20%20%60%C2%BD*%E1%BA%8Bf%E1%B8%A2v%E1%B8%A2&inputs=3&header=&footer=)
Port of [hyper-neutrino's Jelly answer](https://codegolf.stackexchange.com/a/229980/80050)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
“+--“|  ”ẋḊ¥⁺€
```
[Try it online!](https://tio.run/##y0rNyan8//9RwxxtXV0gWaOg8Khh7sNd3Q93dB1a@qhx16OmNf8Pt0f@/28KAA "Jelly – Try It Online")
-2 bytes thanks to Jonathan Allan
Returns a matrix of characters.
```
“+--“|  ”ẋḊ¥⁺€  Main Link
“+--“|  ”       ["+--", "|  "]
           ¥    Apply last two to a list and X
         ẋ      Repeat the list X times
          Ḋ     Remove the first element
             €  To each row,
            ⁺   Do the above
```
[Answer]
# Haskell, 42 bytes
```
n%a=tail$[1..n]>>a
f n=n%[n%"+--",n%"|  "]
```
[Try it online!](https://tio.run/##PcgxCgIxEAXQ3lN8BgO7aAIKlpkTaGUZU0zh4mB2CGvsvHtUBKsH7yaP@7WU3s1JbKJlnXYhWGaW1QSL5pI52nhP248vgHKfRQ0Rs9QThovCM@qi1qBg/nV9tnNbjoZhgo7f/g/RiLQP4ZD7Gw "Haskell – Try It Online")
Defines `f :: Integer -> [String]`.
`[1..n]>>a` means: for each element of `[1..n]`, cycle through all elements of `a`. Then, `tail` removes the first one. So `3%"+--"` evaluates to `"--+--+--"`.
`%` does double duty, first acting on `String`s to make the two grid rows, and then on `[String]` to transform them into whole grid.
(The tempting 39-byte `f n|g<-tail.([1..n]>>)=g[g"+--",g"| "]` is thus foiled by the [monomorphism restriction](https://wiki.haskell.org/Monomorphism_restriction).)
[Answer]
# Excel, 62 bytes
```
=LEFT(REPT(IF(MOD(SEQUENCE(2*A1-1),2),"  |","--+"),A1),3*A1-1)
```
With gridlines turned off, it looks the same as the single string with line feeds.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 37 bytes
```
->n{['  |'*~-n]*n*"
#{['--']*n*?+}
"}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOlpdQaFGXatONy9WK09LiUsZKKKrqw7i2GvXcinV/k/LL1LIVMjMUzDS0zPlUigoLSlWSIvOjIUwuVLzUv4DAA "Ruby – Try It Online")
### [Ruby](https://www.ruby-lang.org/), 37 bytes
A very similar approach, also 37 bytes:
```
->n{['  |'*~-n]*n*"
#{'--+'*~-n}--
"}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOlpdQaFGXatONy9WK09LiUu5Wl1XVxssUKury6VU@z8tv0ghUyEzT8FIT8@US6GgtKRYIS06MxbC5ErNS/kPAA "Ruby – Try It Online")
[Answer]
# APL, 44 bytes
```
{1 1↓⊃⍪/,/⍵ ⍵⍴⊂2 3⍴'+--|  '}
```
`2 3⍴'+--| '` gives:
```
+--
|  
```
`⍵ ⍵⍴⊂2 3⍴'+--| '` gives n×n tiles, and `⍪/,/` joins them together.
For example n = 3:
```
 +--+--+--
 |  |  |  
 +--+--+--
 |  |  |  
 +--+--+--
 |  |  |  
```
And finally `1 1↓⊃` discloses and drops the first column and row.
```
  |  |  
--+--+--
  |  |  
--+--+--
  |  |  
```
Works in both Dyalog APL and GNU APL.
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RqQwXDR22TH3U1P@pdpa@j/6h3qwIQP@rd8qiryUjBGMhQ19bVrVFQUK8F6lAw4kpTMAUA)
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `j`, 19 bytes
```
:`+--``|  `"*$ẋfḢvḢ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=j&code=%3A%60%2B--%60%60%7C%20%20%60%22*%24%E1%BA%8Bf%E1%B8%A2v%E1%B8%A2&inputs=5&header=&footer=)
Ports my Jelly answer. I'll stop for a bit to give other people time to answer.
```
:`+--``|  `"*$ẋfḢvḢ  Full Program
:                    Duplicate X
 `+--`               Push "+--"
      `|  `          Push "|  "
           "         Pair into ["+--", "|  "]
            *        Repeat each X times
             $ẋ      Repeat that X times
               f     Flatten
                Ḣ    Remove first row
                 vḢ  Remove first column from each
j                    flag: output top of stack separated by newlines
```
[Answer]
# [J](http://jsoftware.com/), 34 bytes
```
'| +-'{~<:@+:$#:@6(,:+&2)@$~*&3-1:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/1WsUtHXVq@tsrBy0rVSUrRzMNHSstNWMNB1U6rTUjHUNrf5rcqUmZ@QrpCkYQRjq6jABY3QBk/8A "J – Try It Online")
Consider 3 as input:
* `#:@6...$~*&3-1:` Six in binary `#:@6` expands to `1 1 0` and "input times 3 minus 1" is 8 `*&3-1:`, so we extend `1 1 0` that far:
```
1 1 0 1 1 0 1 1
```
* `(,:+&2)@` Stack that with 2 added to itself:
```
1 1 0 1 1 0 1 1
3 3 2 3 3 2 3 3
```
* `<:@+:$` Now extend that to length "2 times input minus 1":
```
1 1 0 1 1 0 1 1
3 3 2 3 3 2 3 3
1 1 0 1 1 0 1 1
3 3 2 3 3 2 3 3
1 1 0 1 1 0 1 1
```
* `'| +-'{~` And use that to index into the grid characters:
```
  |  |  
--+--+--
  |  |  
--+--+--
  |  |  
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-l`, ~~28~~ ~~24~~ 23 bytes
```
@>*@>:["+--""|  "]XaRLa
```
[Try it online!](https://tio.run/##K8gs@P/fwU7Lwc4qWklbV1dJqUZBQSk2IjHIJ/H///@6Of@NAQ "Pip – Try It Online")
### Explanation
Same idea as [my Python answer](https://codegolf.stackexchange.com/a/230001/16766), implemented a bit more directly:
```
      ["+--""|  "]       List of two strings
                  Xa     Repeat each string n times
                    RLa  Repeat the whole list n times
   @>:                   All but the first item of the list (: forces @> to be
                           lower precedence than X and RL)
@>*                      All but the first item of each string in the list
                         Autoprint (implicit), one string per line (-l flag)
```
[Answer]
# [C (clang)](http://clang.llvm.org/), 71 bytes
```
l;f(n){for(l=n*3,n=n*2*l-l;--n;)putchar(n%l?"|  +--"[n/l%2*3+n%3]:10);}
```
[Try it online!](https://tio.run/##LYzNCgIhFIX38xQXQfAnqRRaZEMPUi1EsIQ7t5im1eSzm0JncT74DpxoIga614o@CZJres4CR1JuQ62tQoPeGPLy9VniI8yCOJ7ZF0Abwy60RW6V08Td7bjfSV9qpgWmkEnIdYD@1kWGESz4xhMcGrXO0HdIIkvf2N7fgl1J/cO6LUOpPw "C (clang) – Try It Online")
```
l=n*3        line length (\n included)
n=n*2*l-l    total characters count
for(..;--n)  while we iterate backwards :
n%l?..:10    > put a return at end of line or..
"|  +--"[n/l%2*3+n%3] > take the proper char to put
```
[Answer]
# [Python 2 or 3](https://docs.python.org/), ~~49~~ ~~46~~ 42 bytes
*-4 bytes thanks to [dingledooper](https://codegolf.stackexchange.com/users/88546)*
```
lambda n:([("+--"*n)[1:],"  |"*~-n]*n)[1:]
```
Returns a list of lines. [Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPSiNaQ0lbV1dJK08z2tAqVkdJQaFGSatONy8WKvI/Ma9YwVYhTcNYk4uroCgzr0QDKKIJZSopaXKl5RcpFOWXK2TmKQBlrLgUIFJAIc3/AA "Python 2 – Try It Online")
### Explanation
It's easy to generate this grid:
```
+--+--+--
|  |  |  
+--+--+--
|  |  |  
+--+--+--
|  |  |  
```
Then we can trim off the first line as well as the first character of each line.
Since the latest golf, the code works a *little* differently:
```
([("+--"*n)[1:],"  |"*~-n]*n)[1:]
   "+--"*n                         # Repeat the horizontal line pattern n times
  (       )[1:]                    # and remove the first character
                "  |"*~-n          # Repeat the other pattern n-1 times
                                   # (trailing spaces aren't required, so
                                   # we don't have to remove anything)
 [             ,         ]         # Put those two strings in a list
                          *n       # Repeat the list n times
(                           )[1:]  # and remove the first element
```
[Answer]
# 6502 machine code, Apple 2, 61 bytes
I got a bit carried away...
$130 - $F3 = $3D (61 decimal) bytes
Listing:
```
0000F3r 1               n := $f0
0000F3r 1               c := $f1
0000F3r 1               ; X register contains n
0000F3r 1  86 F0        grid:   stx n
0000F5r 1  CA                   dex
0000F6r 1  86 F1                stx c
0000F8r 1  A6 F1        @loop: ldx c
0000FAr 1  A9 rr        @cloop: lda #<coldiv
0000FCr 1  A0 rr                ldy #>coldiv
0000FEr 1  20 rr rr             jsr msgoutay
000101r 1  CA                   dex
000102r 1  D0 F6                bne @cloop
000104r 1  20 8E FD             jsr CROUT
000107r 1  C6 F0                dec n
000109r 1  F0 19                beq @done
00010Br 1  A6 F1                ldx c
00010Dr 1  A9 rr        @rloop: lda #<rowdiv
00010Fr 1  A0 rr                ldy #>rowdiv
000111r 1  20 rr rr             jsr msgoutay
000114r 1  CA                   dex
000115r 1  D0 F6                bne @rloop
000117r 1  A9 rr                lda #<rowend
000119r 1  A0 rr                ldy #>rowend
00011Br 1  20 rr rr             jsr msgoutay
00011Er 1  20 8E FD             jsr CROUT
000121r 1  4C rr rr             jmp @loop
000124r 1  60           @done:  rts
000125r 1               
000125r 1               
000125r 1  A0 A0 FC 00  coldiv:    ASZ "  |"
000129r 1  AD AD AB 00  rowdiv:   ASZ "--+"
00012Dr 1  AD AD 00     rowend:  ASZ "--"
000130r 1 
              
```
Example run called with
```
    ldx #4
    jsr grid
```
[![Example Test Run](https://i.stack.imgur.com/pwnue.png)](https://i.stack.imgur.com/pwnue.png)
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 71 bytes
```
n->[print(concat([["  ","--";"|","+"][j+1,t+1]|j<-r]))|t<-r=[2..2*n]%2]
```
[Try it online!](https://tio.run/##DcZBCoAgEADAr8hCoOkK2bHsI8seIjDysIl49O/Waaac9cG7jBSH4EGlPtL09cp1Nk0ESoEDRNig/7HAlO3iml245x0rG9Pbb6TgfZiFp8Aj6dWMDw "Pari/GP – Try It Online")
Thanks to alephalpha for saving 39 bytes.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 46 bytes
```
->n{(2..n*2).map{|x|[" -"[x%=2]*2]*n*"|+"[x]}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNITy9Py0hTLzexoLqmoiZaSUFXKbpC1dYoVguI8rSUarSB/Nja2v8FpSXFCmnRRrFcIBYXlGsW@x8A "Ruby – Try It Online")
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), ~~46~~29 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{⍉1↓⍉⊃,/⍵⍴⊂(⍵+⍵-1)3⍴'|  +--'}
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=q37U22n4qG0ykHrU1ayj/6h366PeLY@6mjSALG0g1jXUNAaKqNcoKGjr6qrXAgA&f=S1Mw4kpTMAZiEyA2BQA&i=AwA&r=tryAPL&l=apl-dyalog&m=train&n=f)
* saved 17 thanks to @Razetime tips!
(⍵+⍵-1)3⍴'| +--' we build the entire column e.g.
```
| 
+--
|  
+--
| 
```
Then :
```
⍵⍴⊂    ⍝  n copies of that column 
,/     ⍝  concatenate 
⊃      ⍝  disclose
⍉1↓⍉   ⍝ transpose, drop line, re transpose 
```
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 841 bytes
```
->>>>>+++++[>+++++>+++++<<-],[+>-[<-->-]>[>>>>+>+<<<<<-]>>>,]+++[<+++>-]+[-<<<<<[->+>+>+<<<]>>>[<<<+>>>-]<<<+]->>>>>->->->>>[<+++++++++[>+>+>+<<<-]>>>>>>]->--[<<+>>-]>[<<+++++>>-]<<[[->>>>>+<<<<<]<]<+[--[>>>>>>>..>.<<<<<<<<-]+<<<<<[[<<<+>>>-]<<<[->>>+>+>+<<<<<]>>>>+>-<[>[[-]<[-]<->>>>>[+++++++++>>>>>]<<<<<+>>>>]<[--<<<<<]]>[++>>>--<<[>>>>>]>]<<]<<+]++++++++++.[-]-<+[--[->>++[-<<<+[->>[-]<<[<+>-]<[>+>>+<<<-]<<<<+]-[>>>>>]<<<+[--[>[>+>-<<-]>[<+>-]>+[->->>>..>.<<<<<]>+[->>>+++++++++++++..--.-----------<<<]<<<<-]+<<<<<[[<<<+>>>-]<<<[->>>+>+>+<<<<<]>>>>+>-<[>[[-]<[-]<->>>>>[+++++++++>>>>>]<<<<<+>>>>]<[--<<<<<]]>[++>>>--<<[>>>>>]>]<<]<<+]>[>+>+<<-]>[<+>-]>[->>>>+++++++++++++..-------------<<<<]<++++++++++.[-]<]<<]+<<<<<[[<<+>>-]<<[->>+>>+>+<<<<<]>>>>+>-<[>[[-]<[-]<<->>>>>[+++++++++>>>>>]<<<<<+>>>>>]<[--<<<<<]]>[++>>--<[>>>>>]>]<<<]<<+]
```
edit1, thank you for the suggestion by [Radvylf Programs](https://codegolf.stackexchange.com/users/79857/radvylf-programs)
this work by using 5 cells per digit, 1 for original number, 1 for row number, 1 for column number, and 2 for verifying that help to make the number system work.
[Try it online!](https://tio.run/##zVJBTsQwDLznFb17nRNHyx@xfAAkpBUSByTeX2bsULpoBVfSNmljjz0z6dP74/Xt5eP5dd/VOYQjeunZTPMS4hqm6poelecIGGP4uCRBRoimbKEVCmVW5TEpsApWTb5kt9O6GKxe2@q@YFUcIwey0J94ErDO7loRi3k1TVwSSG6kz@nT1gC3JnZDpeByCMpWpzbCUTqNT3eIg6I0rQJIv6Jn43MMZrI8dppHQgJCg8K/hcpEbTQaRVhpfnsn/IgSZ7TUaMlyxNq9OBgsuEextvKHIGcVPVvQW@uMt2OeUxU3xrbm8vHfGFbK5KysT/yOjJ8q@DPc2g27kp6dlH39RzwA/13W37ruCsPGWdbSte8Pnw "brainfuck – Try It Online")
also, I edited the first one(adding "+" version) to get a better result. here
# [brainfuck](https://github.com/TryItOnline/brainfuck)(adding "+" version) ,~~273~~ 198 bytes
```
-[>+>+>+<<<-]>>> >>> >>> >+++++[<+++<+++++<<++++++<++>>>>>-]<<[<+++++>-]>[<+++>-]<<-<++<<<[->>>..>.<<<<]>>.<<<<[->[->+>+<<]>[<+>-]>[>>>>..--.++<<<<-]>>>>..<<<.<<<[->+>+<<]>[<+>-]>[>>..>.<<<-]>.<<<<]
```
[Try it online!](https://tio.run/##ZU5BCoAwDPuK99G@IPQjYwcVBBE8CL5/Zql4sVvXNEu6Lde8n9u9Hr1kdKtRxgJgLSKmL3VfwQOCyDK6GGENqMkRh6BIwxCjGkXu4cTgaFWS3HpPFjlDQjOXL/9BgtDT8tO/Y9nk9N4f "brainfuck – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 43 bytes
```
.+
$*
1
$_¶$_¶
1
+--
T`-+` |`¶.+¶
1A`
%`^.
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRYvLkEsl/tA2EAYytXV1uUISdLUTFGoSDm3T0wYJOiZwqSbE6XH9/28MAA "Retina 0.8.2 – Try It Online") Explanation:
```
.+
$*
```
Convert to unary.
```
1
$_¶$_¶
```
Create `2n` rows of `n` `1`s.
```
1
+--
```
Replace each `1` with `+--`.
```
T`-+` |`¶.+¶
```
Change those to  `|` on alternate lines.
```
1A`
```
Delete the first line of `--+`s.
```
%`^.
```
Delete the leading `+`s or `|`s on each line.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 93 bytes
```
n=>('  |'[r='repeat'](--n)+'  0')[r](n+1).slice(0,-1).split(0).join('\n'+'--+'[r](n)+'--\n');
```
[Try it online!](https://tio.run/##HcoxDgIhEEDRq2w3M8Eh2NgYvMi6BUHWsCEDAWLl3ZG1@3n5h/u45mssnSW/wtjtEPtAWJYvrNVCDSW4DhsyC6nJBmitG4q6km4p@oDmwmeXFDsa0keOgvAUUMCs4D/T2ZPoPnyWllPQKb9xxxtN@gE "JavaScript (Node.js) – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 14 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
╬^û╗i§║╜P◙ƒ═½\
```
[Run and debug it](https://staxlang.xyz/#p=ce5e96bb6915babd500a9fcdab5c&i=2%0A3%0A4%0A5%0A6&m=2)
Similar to the Jelly answer.
[Answer]
# [PowerShell], 53 bytes
```
&{$c=$n-1;@("  |"*$c)*$n -join "`n$(""--+""*$c)--`n"}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNydFNzi9K/a@SZ2vyX61aJdlWJU/X0NpBQ0lBoUZJSyVZU0slT0E3Kz8zT0EpIU9FQ0lJV1dbCSyjq5uQp1T7/z8A "PowerShell Core – Try It Online")
]