[Question]
  [
# Challenge
Create a function or program that, when given an integer `size`, behaves the following way:
If `size` is equal to 1, output
```
┌┐
└┘
```
If `size` is greater than 1, apply the following substitutions :
| Source | Target |
| --- | --- |
| `┌` | `┌┐``└┌` |
| `┐` | `┌┐``┐┘` |
| `└` | `┌└``└┘` |
| `┘` | `┘┐``└┘` |
**Note:** this is basically a Unicode box-drawing version of the [T-Square fractal](https://www.wikiwand.com/en/T-square_(fractal)).
If it makes things easier for you, you may make the base case correspond to `0`, as long as you specify in your answer.
The program should output anything that is isomorphic to a grid, so a multiline string, an array of strings, an array of arrays of chars, whichever is more comfortable. You may use a different set of characters than `┌┐└┘` (such as 1234, ABCD, etc.) if you want.
Leading and trailing spaces are allowed if you choose to work with strings.
Please specify what output format your code is returning.
# Test Cases
`1`
```
┌┐
└┘
```
`2`
```
┌┐┌┐
└┌┐┘
┌└┘┐
└┘└┘
```
`3`
```
┌┐┌┐┌┐┌┐
└┌┐┘└┌┐┘
┌└┌┐┌┐┘┐
└┘└┌┐┘└┘
┌┐┌└┘┐┌┐
└┌└┘└┘┐┘
┌└┘┐┌└┘┐
└┘└┘└┘└┘
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the lowest byte count for each language wins!
  
[Answer]
# JavaScript (ES6), 108 bytes
Returns an array of strings, with `0123` instead of `┌┐└┘`.
```
f=(n,a=[w="01","23"])=>n?f(n-1,[...a,...a].map((s,i)=>i<w|i/w/3?s+s:s.slice(0,w)+a[i-w]+s.slice(-w)),w*=2):a
```
[Try it online!](https://tio.run/##VY8xboQwEEV7TjFy5QnGsEsqst69Q5oUhMIiQLwitsWwcZHkBilSUOR8XIRApEjZZr70vubPn7N@1VQPxo@JdU/NsrSKW6FVGRTLdkywfc4qVEd7arlNdqKUUmqxjUq@aM85CbPa5hDeTRrS/EQxFSSpN3XDMxEw1qVJQhX/sSQginCj9ljopXaWXN/I3nWc3esA7jL6y1gwjP5bLc8RoyvEHu2DGZ/BOxoTP7i6ITK22zZbN3ALCrI7sHCA21XiGOEtArgOtfj7AoE6Asmh8b1eC6Yy7QTUG2Tz9DlPX/M0zdM3K@sKUZ6dsdt1tjb6WH4A "JavaScript (Node.js) – Try It Online")
### How?
This is a rather straightforward recursive construction of the pattern and is probably not the shortest method.
Below is an example for the 2nd iteration, with **w = 2**.
```
   0123  0123 4567  0123 4567
0  ABCD  ABCD|ABCD  ABCD|ABCD  \__ i < w -> s + s
1  EFGH  EFGH|EFGH  EFGH|EFGH  /
2  IJKL  IJ..|..KL  IJ**A****B**|**C****D**KL  \
3  MNOP  MN..|..OP  MN**E****F**|**G****H**OP   \
         ----+----  ----+----    }-- s.slice(0, w) + a[i - w] + s.slice(-w)
4        AB..|..CD  AB**I****J**|**K****L**CD   /
5        EF..|..GH  EF**M****N**|**O****P**GH  /
6        IJKL|IJKL  IJKL|IJKL  \__ i ≥ 3w -> s + s
7        MNOP|MNOP  MNOP|MNOP  /
```
### Commented
```
f = (                     // f is a recursive function taking:
  n,                      //   n = number of iterations
  a = [                   //   a[] = output array initialized to:
    w = "01",             //     the pattern "01" (we also initialize w to "01")
    "23"                  //     the pattern "23"
  ]                       //
) =>                      //
  n ?                     // if n is not equal to 0:
    f(                    //   do a recursive call:
      n - 1,              //     decrement n
      [...a, ...a]        //     repeat a[] twice
      .map((s, i) =>      //     for each string s at index i in this array:
        i < w |           //       if i is less than w
        i / w / 3 ?       //       or i is greater than or equal to w * 3:
          s + s           //         just double the previous row
        :                 //       else:
          s.slice(0, w) + //         take the first half of s
          a[i - w] +      //         append the row i - w of the previous pattern
          s.slice(-w)     //         append the 2nd half of s
      ),                  //     end of map()
      w *= 2              //     double w
    )                     //   end of recursive call
  :                       // else:
    a                     //   return a[]
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~29~~ 21 bytes
```
┌Ｆ÷Ｘ²…⁰Ｎ²«Ｃιι‖ＢＯ⌈⊗ι
```
[Try it online!](https://tio.run/##DcwxCsIwFIDhuT3Fo9N7EEEKLrpply5aeoO0fdVATEJIKkXcHTp6wl4kdv35@PuH9L2VOqXGKxOwWH9LQad8tB6wNqFSkxoYG/tij6WAVpo7415AbVwM1/jstk5EAkoieOfZxboZlQC1TbKWR819OMcQ2I96vk3stXR4XJevgMrGTvOAijb7SemQdpP@Aw "Charcoal – Try It Online") Link is to verbose version of code. 1-indexed. Explanation:
```
┌
```
Print a quarter of the initial box. This gets fixed up on the first loop iteration. Note that while this character is not in Charcoal's code page, Charcoal has an escape sequence that encodes this character using three bytes; this sequence is not shown although the deverbosifier does account for it correctly.
```
Ｆ÷Ｘ²…⁰Ｎ²«
```
Take the powers of two from `1` up to (but not including) `2ⁿ`, but then integer divide them by 2.
```
Ｃιι
```
Make a copy of the current figure, overwriting the bottom right quarter of the figure. (Except that `i` is zero on the first loop, so nothing happens.)
```
‖ＢＯ⌈⊗ι
```
Reflect the (original three quarters of) the figure to complete the new iteration.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~103~~ 101 bytes (UTF 8) or ~~95~~ 93 bytes (ASCII)
```
->n{n<1?%w{┌┐ └┘}:(q=f[n-1];(-k=1<<n)...k).map{|i|s=q[i]*2;(t=i+j=k/2)/2%k<j&&s[j,k]=q[t];s}}
```
A function which returns an array of strings.
For `n=0` the output is as follows:
```
UTF 8 ┌┐      Or   ASCII (my preferred   pq
      └┘            character choice)    bd
```
For higher values of `n` the function is called recursively to build up a square of double the proportions of the previous iteration (total 4 copies) line by line. For the middle rows, the lines are modified as necessary to overwrite a fifth copy of the previous iteration onto the centre of the pattern.
[Try it online!](https://tio.run/##DcoxDsIgFADQq3RpAyo0xU34ehDCoAMJEEkrNMZQbuDgwOD5uAj65vdYb6@moZGzT15Ml/6ZannX8ulqKbV88wktoKUnk@KIOJiE8JhS6jC9X@e0mS3AIo3aMY4imL0FNzI8st4JOwxB2oNT/xAVDzm3eY2h0/Ko2g8 "Ruby – Try It Online")
TIO link shows the UTF 8 version for easy verification. substituting the box characters with `pq bd` (or other ASCII characters) reduces the code to 93 bytes.
[Answer]
# [J](http://jsoftware.com/), ~~46~~ 42 bytes
```
([`(<@;~@(-:+i.)@#@[)`]},~@,.~)@[&0 i.@2 2
```
[Try it online!](https://tio.run/##VctBC4IwAIbh@37FR0Fu5IauiLCEUdApIrpKoJjaIpw4O4TkX1927PAensP7cBPhlYgjePARIBrjAvvL8eBoktKt2gyK8miuBVNTlbD0@vEH5YuBqWQWQAslIR0j5LQTOBvboWlNXlir6wrlq847bWqUpkWt8wI3bZtn9iZVLGi4QriGHP9lnwlW5Hejon4oCakQkB/hcc69keE/5T8X7gs "J – Try It Online")
* `i.@2 2` returns:
```
 0 1
 2 3
```
* `(...)@[&0` Apply the verb (...) iteratively "input" number of times.
* `(<replace logic> ,~@,.~)` - `,~@,.~` first zips the current input with itself `,.~`, so with the starting input that becomes:
```
 0 1 0 1
 2 3 2 3
```
and then appends that to itself `,~@`:
```
 0 1 0 1
 2 3 2 3
 0 1 0 1
 2 3 2 3
```
giving us the original input repeated 4 times in a square.
* Next we replace the "center" with the original input. Imagine filling in a hole like so:
```
  0 1 0 1                0 1 0 1
  2     3   +  0 1  =    2 0 1 3
  0     1      2 3       0 2 3 1
  2 3 2 3                2 3 2 3
```
* Here we're using the gerund form of Amend `}`, and all the rest is mechanics to specify which coordinates we replace:
* `(<@;~@(-:+i.)@#@[)` That entire phrase, verbosely, converts (in our example) the 2x2 original input matrix into the J double boxed:
```
 ┌─────────┐
 │┌───┬───┐│
 ││1 2│1 2││
 │└───┴───┘│
 └─────────┘
```
which is how we tell Amend: "Replace the intersection of rows 1 and 2, and columns 1 and 2 with..."
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~60~~ 55 bytes
```
Nest[Flatten[q/. 5-#->#&/@#&/@#,q]&,q={{1,3},{2,4}},#]&
```
[Try it online!](https://tio.run/##Hcw9CsJAFATgq8iupHoafxvREAUFG8UfsFgXWcIzLujGrC9FCPEEFhYpPJ8XiTHFfEwzc1N0wZsiHajyPClX@CCxuCoiNCJ2241hi7c87rh@HYilA/Eky7rQzyHrwSDPgUun3CQayZ9po2x6sJpQNNcJ3ROCHVltwn00Swmn1qpU8LHHjob9/6rGpHTE2Z8Hl8jnblufloYwRDvyMvYtXgwqi9p37YflQmhZrZ67QJnnVpkQRQeGsvwB "Wolfram Language (Mathematica) – Try It Online")
Returns a matrix of integers - uses `1234` for `┌└┐┘`.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~217~~ \$\cdots\$ ~~119~~ 102 bytes
Saved ~~9~~ a whopping 35 bytes thanks to [Danis](https://codegolf.stackexchange.com/users/99104/danis)!!!  
Saved ~~2~~ 5 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203/att)!!!
```
f=lambda n:n and[[(j,c)[j+c==3]for c in r for j in(i,i+1)]for r in f(n-1)for i in(0,2)]or[[0,1],[2,3]]
```
[Try it online!](https://tio.run/##jVTNboMwDL7zFLkl6dKpQKVJSLnuJTIODMIa1gaEmLQfbU@www4c9ny8CEug1UJb03KwTOzP9uc4rt6aTanDvs/5Ntk9ZgnSkUaJzoQgBUupKG5SzsM4L2uUIqVRjaxaGJUopm58Ophqa8qJXvrU/iprXrGAxmUtxIr5MRMBC@O4z2SOKrKjkYfMZ323FrqLqlrphmB8W5QGi7v2u2t/urbt2l8s5JBEWs8tpZ58rWTayAxxRGx4ZOIjkwCZDGw8YMg5Hg9C@2dU6@dAxoMjoCunQQb3k4Au5iS4izxgRu99Kcd5/ss6V7iLnJJw5QwhSMJEIR1uwKHI6xvjyNmGQQxmGwnxmG0wxGm28RCnKQ9XTobg8n0cD8eF@zgzNHP3cX6YrhtgiBM82BAneOAhHX4IkDQPhHrpRqbPsraLBD@8BHfrFDM0aH6IqTfsMjbsnXdVkTrRT5KsKTssoP0aG3dXju@Nu@Yf6jMyWGtoeE7UqFakoY7zPrFoOJexa8BLvAgWi@WXov0f "Python 3 – Try It Online")
Uses integers \$0,1,2,3\$ instead of chars `┌`,`┐`,`└`,`┘`.  
Inputs a zero-base integer \$n\$ and returns the \$2^{n+1}\times 2^{n+1}\$ T-Square fractal as a list of strings.
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), ~~36~~ 31 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{⊃⍪/,/{⍵@(⌽⍵=⊖)x}¨⍵}⍣⎕⊢x←2 2⍴⍳4
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkGXI862tP@Vz/qan7Uu0pfR7/6Ue9WB41HPXuBtO2jrmmaFbWHVgDZtY96FwM1PepaVAHUZqRg9Kh3y6PezSb/gfr/p3EZcqVxGQGxMRCbALEpAA "APL (Dyalog Unicode) – Try It Online")
A dfn submission which takes the number as left argument.
Uses `⎕IO←0` (0-indexing).
The box is represented as
```
01
23
```
which is then substituted exactly according to the question spec.
-5 bytes from Adám.
## Explanation
```
{⊃⍪/,/{⍵@(⌽⍵=⊖)x}¨⍵}⍣⎕⊢x←2 2⍴⍳4
                       x←2 2⍴⍳4  store 0 1 in x
                                       2 3
                    ⍣⎕⊢          apply the following n times to the value of x:
{                ¨⍵}             substitute each number ⍵ with:
      {⍵@      x}                replace the following with ⍵ in the value of x:
         (⌽⍵=⊖)                  position of ⍵, flipped diagonally
  ⍪/,/                           join all the submatrices together
 ⊃                               and remove boxing.
```
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 42 bytes
```
{⍵≡0:2 2⍴⍳4⋄m⊣@((2*⍵-1)+⍳,⍨2*⍵)⍪⍨,⍨m←∇⍵-1}
```
```
{⍵≡0:2 2⍴⍳4⋄m⊣@((2*⍵-1)+⍳,⍨2*⍵)⍪⍨,⍨m←∇⍵-1}
 ⍵≡0:2 2⍴⍳4                                 ⍝ if ⍵ is 0 return the first result
           ⋄                                ⍝ otherwise
                                   m←∇⍵-1   ⍝ assign the last result to m
                               ⍪⍨,⍨         ⍝ duplicate in both directions
               ((2*⍵-1)+⍳,⍨2*⍵)             ⍝ indices corresponding to the middle section
            m⊣@                             ⍝ replace with m
```
Produces the fractal recursively using a pattern I spotted where you make 4 copies of the previous one and replace the middle. (I'm not sure if this works in general though, so if you have outputs for 4+ that would be great)
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qn/6O2CQb/qx/1bn3UudDAykjB6FHvlke9m00edbfkPupa7KChYaQFlNU11NQGCus86l0B5ms@6l0FZIP4uUAjHnW0gxXV/k8D8Xr7HnU1P@pdAzTr0HrjR20TgVYFBzkDyRAPz@D/j3rnKhSllpQW5RUrlBZn5qUrGCgYKhgpGOsoZOalpFYAyZJ8hZKMVIXkjMSixOSS1KJihbT8IoVEhaTUEiBPISWzuCAnsZJL/dGUnkdTJjyaMuXRlBnq0WkKBrGYYoZYxIywiBnHAgA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 30 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
3Ý2ô©IGNoTS-U2δиD«DÅsε®NèXǝ}Xǝ
```
Port of [*@Jonah*'s J answer](https://codegolf.stackexchange.com/a/218673/52210), so make sure to upvote him as well!
Outputs as a matrix, with `0123` for `┌┐└┘` respectively.
[Try it online](https://tio.run/##AVcAqP9vc2FiaWX//zPDnTLDtMKpSUdOb1RTLVUyzrTQuETCq0TDhXPOtcKuTsOoWMedfVjHnf99SsK7M8OdIuKUjOKUkOKUlOKUmCLigKH/NP8tLW5vLWxhenk) or [verify the first input amount of test cases](https://tio.run/##yy9OTMpM/e/pquSZV1BaYqWgZO@nw6XkX1oC4en8Nz481@jwlkMr/dz98kOCdUONzm25sMPl0GqXw63F57YeWud3eEXE8bm1QPy/1uvQbqBypUdTeh5NmfBoypRHU2YoPWpYqHNom/1/s/@6unn5ujmJVZUA) (the footers transliterate it to the unicode boxes to pretty-print).
**Explanation:**
```
3Ý                # Push list [0,1,2,3]
  2ô              # Split it into parts of size 2: [[0,1],[2,3]]
    ©             # Store this 2x2 matrix in variable `®` (without popping)
     IG           # Loop `N` in the range [1,input):
       No         #  Push 2 to the power `N`
         TS-      #  Subtract [1,0] to create a pair: [2^N-1,2^N]
            U     #  Pop and store this pair in variable `X`
        δ         #  Map over each row of the matrix:
       2 и        #   And repeat it
                  #  (i.e. [[0,1],[2,3]] becomes [[0,1,0,1],[2,3,2,3]])
          D«      #  Merge a copy of itself:
                  #   [[0,1,0,1],[2,3,2,3],[0,1,0,1],[2,3,2,3]]
       D          #  Create a copy of the matrix
        Ås        #  Pop and push its middle two rows
          ε       #  Map over those two rows:
           ®      #   Push matrix [[0,1],[2,3]] from variable `®`
            Nè    #   Get the M'th row of this matrix based on the 0-based map-index `M`
              Xǝ  #   Insert those two values at indices `X` into the current row
          }Xǝ     #  After the map: insert the modified middle rows at indices `X` into
                  #  the matrix
                  # (after the loop, the resulting matrix is output implicitly)
```
]