[Question]
  [
You can depict a [triangular number](https://en.wikipedia.org/wiki/Triangular_number), T(N), by writing one 1 on a line, then two 2's on the line below, then three 3's on the line below that, and so on until N N's. You end up with a triangle of T(N) numbers, hence the name.
For example, T(1) through T(5):
```
1
1
22
1
22
333
1
22
333
4444
1
22
333
4444
55555
```
To keep things nicely formatted we'll use the last digit of the number for N > 9, so T(11) would be:
```
1
22
333
4444
55555
666666
7777777
88888888
999999999
0000000000
11111111111
```
Now pretend like each row of digits in one of these triangles is a 1-by-something [polyomino](https://en.wikipedia.org/wiki/Polyomino) tile that can be moved and rotated. Call that a row-tile.
For all triangles beyond T(2) it is possible to rearrange its row-tiles into a W×H rectangle where W > 1 and H > 1. This is because [there are no prime Triangular numbers above N > 2](https://math.stackexchange.com/a/1012326). So, for N > 2, we can make a rectangle from a triangle!
(We're ignoring rectangles with a dimension of 1 on one side since those would be trivial by putting every row on one line.)
Here is a possible rectangle arrangement for each of T(3) through T(11). Notice how the pattern could be continued indefinitely since every odd N (except 3) reuses the layout of N - 1.
```
N = 3
333
221
N = 4
44441
33322
N = 5
55555
44441
33322
N = 6
6666661
5555522
4444333
N = 7
7777777
6666661
5555522
4444333
N = 8
888888881
777777722
666666333
555554444
N = 9
999999999
888888881
777777722
666666333
555554444
N = 10
00000000001
99999999922
88888888333
77777774444
66666655555
N = 11
11111111111
00000000001
99999999922
88888888333
77777774444
66666655555
```
However, there are plenty of other ways one could arrange the row-tiles into a rectangle, perhaps with different dimensions or by rotating some row-tiles vertically. For example, these are also perfectly valid:
```
N = 3
13
23
23
N = 4
33312
44442
N = 5
543
543
543
541
522
N = 7
77777776666661
55555444433322
N = 8
888888881223
666666555553
444477777773
N = 11
50000000000
52266666634
57777777134
58888888834
59999999994
11111111111
```
# Challenge
Your task in this challenge is to take in a positive integer N > 2 and output a rectangle made from the row-tiles of the triangles of T(N), as demonstrated above.
As shown above, remember that:
* The area of the rectangle will be T(N).
* The width and height of the rectangle must both be greater than 1.
* Row-tiles can be rotated horizontally or vertically.
* Every row-tile must be depicted using the last digit of the number it represents.
* Every row-tile must be fully intact and within the bounds of the rectangle.
The output can be a string, 2D array, or matrix, but the numbers must be just digits from 0 through 9.
The output does not need to be deterministic. It's ok if multiple runs produce multiple, valid rectangles.
**The shortest code in bytes wins!**
  
[Answer]
# [Python 2](https://docs.python.org/2/), 59 bytes
```
n=input()
c=~n%2
while c<n:print`n%10`*n+`c%10`*c;n-=1;c+=1
```
[Try it online!](https://tio.run/##JcxNCoMwFEXh@V1FCQhtRfCl/9rsJfAIGCi3oaRoJ916RJ2dwcdJvzy8acs4xFfYSRemoMaYQheZvnl/gLo/K4sN6JNd@kRmz0paf2TtdQ3t2TjptXZSVoDlcsIZF1xxwx0PSAsRiJ0B "Python 2 – Try It Online")
Prints like:
```
55555
44441
33322
```
It looks kind-of redundant to update `n-=1;c+=1` where sum `n+c` remains unchanged. I feel like there's a better way, but I haven't seen it so far. [Bounty is up for grabs!](https://codegolf.meta.stackexchange.com/a/18334/20260)
---
**60 bytes**
```
n=input()
b=a=n/2
while n-b:b+=1;print`a%10`*a+`b%10`*b;a-=1
```
[Try it online!](https://tio.run/##JYxRCsIwEAX/3ykkIKil2I3a2pa9S7ISaEDWUFK0p49Y/wZmmLTm6aW2vKf4DDsawic8jDFFOWpa8uEIYc96tvgXWssgFdOY5qjZ@T017uQrJxvI6Gumsjn8NhdccUOLDnf0oAZEIPsF "Python 2 – Try It Online")
Prints like:
```
22333
14444
55555
```
Based on ideas by @newbie.
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~49~~ ~~47~~ ~~34~~ ~~38~~ 35 bytes
*3 bytes saved thanks to @Bubbler!*
```
{10|(⌈⍵÷2)↑↑,/⍴⍨¨⍉↑((⍳⍵)-2|⍵)(⌽⍳⍵)}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RqQ4MajUc9HY96tx7ebqT5qG0iEOnoP@rd8qh3xaEVj3o7gXwNjUe9m4EqNHWNakAUUMNeqEgt0BiFQysUjLWBAhYA)
```
                  ⍉↑                    ⍝ concat each pair in 
                     ((⍳⍵)     )(⌽⍳⍵)   ⍝ 1..n and n..1 (into 2×n matrix)
                          -2|⍵           ⍝ concats n-1..0 if n is odd
               ⍴⍨¨                       ⍝ repeat each item *itself* times 
            ↑,/                          ⍝ flatten
     (⌈⍵÷2)↑                             ⍝ take first n/2 rows
10|                                      ⍝ for each item, take the last digit
0 7      7 7 7 7 7 7 7      7 7 7 7 7 7 7
1 6  =>  1 6 6 6 6 6 6  =>  1 6 6 6 6 6 6
2 5      2 2 5 5 5 5 5      2 2 5 5 5 5 5
3 4      3 3 3 4 4 4 4      3 3 3 4 4 4 4
4 3      4 4 4 4 3 3 3
5 2      5 5 5 5 5 2 2
6 1      6 6 6 6 6 6 1
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~16~~ ~~15~~ 14 bytes
```
Ýεθy×}2äí`RøJ»
```
[Try it online!](https://tio.run/##ASIA3f9vc2FiaWX//8OdzrXOuHnDl30yw6TDrWBSw7hKwrv//zEy "05AB1E – Try It Online")
[Answer]
# JavaScript (ES8), ~~72 71~~ 68 bytes
Returns a string.
```
n=>(g=k=>k<n?(h=k=>''.padEnd(k,k%10))(k)+h(n--)+`
`+g(k+1):'')(~n&1)
```
[Try it online!](https://tio.run/##XcixDoIwEADQna@4RXuXE2LjphxOrn4DDVCQkisB42L016uubi9vdA@3Nsttvuca2y55SSoV9hKkCqWecfjJmGJ27UVbDLuwsXsiDMQDap4T11nNPQa2dDSG8K1bS8nHBRUEDidQKAWs/YKZ4JkBNFHXOHXFFHs0VzHAoPT3HpUoe6UP "JavaScript (Node.js) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 24 bytes
```
ＮθＥ…÷θ²θ⭆⟦⊕ι⁻｜θ¹⊕ι⟧⭆λ﹪λχ
```
[Try it online!](https://tio.run/##VYyxCsIwEIZ3n6LjBSpYJ6GbuHRoFR3FISZHPUgvTZrUx4@Jkx4cHP//fade0isrTUodzzEMcXqiByfazcUTB@jlDFfJI0LH4UQraQRXV3tRVy7vLWRqLNC9Y@VxQg6ogXLVE8cFjhTetODZF6vJ8T8mHr8/TLasjsaWq9mJ77QpHdJ2NR8 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｎθ
```
Input `N`.
```
Ｅ…÷θ²θ
```
Loop rows from `N/2` to `N`. (Due to the increments in the code below, `N/2` is excluded and `N` is included. I could have put the increments here for the same byte count.)
```
⭆⟦⊕ι⁻｜θ¹⊕ι⟧
```
Each row contains two row-tiles, one for the row and one for `N|1` minus the row. (If `N` is odd then this last row-tile is empty.)
```
⭆λ﹪λχ
```
Each row-tile consists of copies of its last digit.
[Answer]
# [Erlang (escript)](http://erlang.org/doc/man/escript.html), 109 bytes
Seems huge in comparison with other answers.
```
t(A,B)when A<B->"";t(A,B)->[string:copies([X rem 10+48],X)||X<-[A,B]]++"
"++t(A-1,B+1).
t(N)->t(N,1-N rem 2).
```
[Try it online!](https://tio.run/##JYyxCsMgGIR3n0KcFP1DLR3aNAjJA2QWxCEEmwqNCSpkybtbaW@44fi@c/EzhQVcmqPfc0El014M7Hi7gPtuAEXI8z@BMilHH5Z23nbvEjUaR7dieeG3uxWanafuwFTUWs4JIpxXEaQYuGQNynSsF7WFhPEnXllT1skHaizDoBCu8Vv7OqLPjmb6YBX4Ag "Erlang (escript) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-n`, 43 bytes
```
@a=map$_%10x$_,$_&1^1..$_;say$_,pop@a for@a
```
[Try it online!](https://tio.run/##K0gtyjH9/98h0TY3sUAlXtXQoEIlXkclXs0wzlBPTyXeujixEihQkF/gkKiQll/kkPj/v8W//IKSzPy84v@6vqZ6BoYG/3XzEgE "Perl 5 – Try It Online")
[Answer]
# Java 11, 89 bytes
```
n->{for(int c=~n&1;c<n;)System.out.println((n%10+"").repeat(n--)+(c%10+"").repeat(c++));}
```
Port of [*@xnor*'s Python answer](https://codegolf.stackexchange.com/a/203140/52210), so make sure to upvote him!!
[Try it online.](https://tio.run/##bY/BCsIwEETvfsUiKFlKg8FjrH@glx7FQ0xTidZtadOClPrrda16ES8LOzvsvLmYzsSX7DrawjQN7IynfgbgKbg6N9bB/rUCdKXPwArWgVCzNMx4NMEEb2EPBMlI8bbPy3ry2ORBS6XthjSm9ya4myzbIKuajwUJQQu1iuZzlLWrnAmC4hgjYX9UG0WIehj1K6tqTwVnfSInnhvTijTw0/PhCAbfqF8Gn6w1@E2ilIY/DIiTG4Ak9@Kkd6thfAI)
**Explanation:**
```
n->{                            // Method with integer parameter and no return-type
  for(int c=~n&1;               //  Temp-integer `c`, starting at 0 if the input is odd;
                                //  or 1 if even
      c<n;)                     //  Loop as long as this `c` is smaller than the input `n`:
    System.out.println(         //   Print with trailing newline:
      (n%10                     //     The last digit of `n`
           +"")                 //     converted to String
               .repeat(n        //     repeated `n` amount of times
                        --)     //     After which `n` is decreased by 1 with `n--`
      +                         //    Appended with:
       (c%10                    //     The last digit of `c`
            +"")                //     converted to String
                .repeat(c       //     repeated `c` amount of times
                         ++));} //     After which `c` is increased by 1 with `c++`
```
[Answer]
# [J](http://jsoftware.com/), ~~41~~ 33 bytes
-8 bytes thanks to Bubbler!
```
10(|-:@##"1~@{.],.|.)2&|@>:}.i.,]
```
[Try it online!](https://tio.run/##bcuxCsIwFIXhvU9xSaBNaHJI6iIRy0XBSRxcJZNYjIsP0NRXj7WuHc7ww3deRaAZaB@oIUOOwjwLOl7Pp@KdyjawlMJ/eEQ0yNBdnbkPExJMLJcDyLvcg21YlFpj1Rr7KZ5W4KKUFBLzJeq/TeBb622XR3DU0cxtK1097s83qd2g635DLSVsyxc "J – Try It Online")
# [K (oK)](https://github.com/JohnEarnest/ok), ~~41~~ ~~38~~ 32 bytes
-6 bytes thanks to ngn!
```
{(x%2)#10!{x}#'(a-2!x),'|a:1+!x}
```
[Try it online!](https://tio.run/##y9bNz/7/P82qWqNC1UhT2dBAsbqiVlldI1HXSLFCU0e9JtHKUFuxovZ/mrqxtqLlfwA "K (oK) – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~85~~ 82 bytes
Saved 3 bytes thanks to [newbie](https://codegolf.stackexchange.com/users/89856/newbie)!!! 
```
i;c;f(n){for(c=-n%2;++c<n;--n,puts(""))for(i=0;i<n+c;)putchar((i++<n?n:c)%10+48);}
```
[Try it online!](https://tio.run/##HYxBCsIwEEX3OUUIFGaIgVa7ECfFi7gpA9EEHEusq5Czx@jy/cd/7O7MrUViCiBYwisDL06GI1nLXsg5OWyf/Q3GIP5sXEaKXiwT9p0fawaI1nq5yoVxmEY7n5Fqe65RAIv6f2TXaTlR8tPcuwl1UTpAQlJ6y90GMDcxHauq7Qs "C (gcc) – Try It Online")
Port of [xnor's Python answer](https://codegolf.stackexchange.com/a/203140/75681) so make sure to upvote him!!!
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~64~~ 62 bytes
```
->n{c=1&~n;n,c=n-1,-~c,puts("#{n%10}"*n+"#{c%10}"*c)while c<n}
```
[Try it online!](https://tio.run/##JczdCoJAEEDh@3mKwSi0dHHsn9peJWhaU7BR1CVD9NW3xKvzXZ3aPr4u1S66Sc@aVqNcJGQtEYXRyGFl28b3Fr0sKR68tWz@5tkcfLK8MMhXGdxMv0ONL9M2irPyXam2vOdYm4atQcmLABBT5XdTpzEYebot7GAPBzjCCc5AMRABJT8 "Ruby – Try It Online")
Based on @xnor's Python answer, thanks!
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 42 bytes
```
10|{⍵=1:1 1⍴1⋄2|⍵:⍵⍪∇⍵-1⋄(⍳∘≢,1+⊢,⊢/)∇⍵-1}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///39CgpvpR71ZbQytDBcNHvVsMH3W3GNUARayA@FHvqkcd7UCGLkhY41Hv5kcdMx51LtIx1H7UtUgHiPU1YQpq/6c9apvwqLfvUd9UT/9HXc2H1hs/apsI5AUHOQPJEA/P4P9pCsZcurq6XGkKJlDaFEobGgEA "APL (Dyalog Unicode) – Try It Online")
A fresh approach using recursion, though not very short.
### How it works
```
10|{⍵=1:1 1⍴1⋄2|⍵:⍵⍪∇⍵-1⋄(⍳∘≢,1+⊢,⊢/)∇⍵-1}
           ⍝ Input: n
⍵=1:1 1⍴1  ⍝ Base case: If n=1, give a 1x1 matrix of 1
2|⍵:⍵⍪∇⍵-1  ⍝ For odd n, prepend n copies of n on the top
(⍳∘≢,1+⊢,⊢/)∇⍵-1  ⍝ For even n...
       ⊢,⊢/       ⍝ append its own last column to its right
     1+           ⍝ add 1 to all elements
 ⍳∘≢,             ⍝ prepend a column of 1..(number of rows) to its left
10|{...}  ⍝ Apply modulo 10 to all elements
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
_Ḷ€ZŒHṚ;"¥/%⁵
```
A monadic Link accepting an integer which yields a list of lists of integers in \$[0,9]\$.
**[Try it online!](https://tio.run/##ASYA2f9qZWxsef//X@G4tuKCrFrFkkjhuZo7IsKlLyXigbX/w4dZ//8xMQ "Jelly – Try It Online")** (footer just reformats the output list of lists)
I feel there may be shorter.
### How?
```
_Ḷ€ZŒHṚ;"¥/%⁵ - Link: integer, n
  €           - for each (i) in (implicit range [1..n])
 Ḷ            -   lowered range (i) -> [0..i-1]
_             - (n) subtract (vectorised across that) -> [[n],[n,n-1],...,[n,n-1,...,1]]
   Z          - transpose -> [[n]*n,[n-1]*(n-1),...,[1]]
    ŒH        - split into half (first half longer if n is odd)
          /   - reduce (this list of two lists) by:
         ¥    -   last two links as a dyad:
      Ṛ       -     reverse (the first half)
        "     -     zip together applying:
       ;      -       concatenation
            ⁵ - literal ten
           %  - modulo
```
---
An alternative first three bytes is `rRṚ`
[Answer]
# [J](http://jsoftware.com/), ~~30~~ 29 bytes
```
10(|-:@#$]#~@,"0|.)2&|0&,1+i.
```
[Try it online!](https://tio.run/##y/qvpKegnqZga6WgrqNgoGAFxLp6Cs5BPm7/DQ00anStHJRVYpXrHHSUDGr0NI3UagzUdAy1M/X@a3KlJmfkK2hYp2mq2SkYK5gomCoYGikYGv8HAA "J – Try It Online")
J's reshape `$` is so weird that it works in place of take `{.` when the left is positive singleton (regardless of what comes on the right).
---
# [J](http://jsoftware.com/), 30 bytes
```
10(|-:@#{.]#~@,"0|.)2&|0&,1+i.
```
[Try it online!](https://tio.run/##y/qvpKegnqZga6WgrqNgoGAFxLp6Cs5BPm7/DQ00anStHJSr9WKV6xx0lAxq9DSN1GoM1HQMtTP1/mtypSZn5CtoWKdpqtkpGCuYKJgqGBopGBr/BwA "J – Try It Online")
Yet another case of [repeat-bind (dyadic `&`)](https://codegolf.stackexchange.com/a/195891/78410) winning over other approaches.
### How it works
```
10(|-:@#{.]#~@,"0|.)2&|0&,1+i.   NB. input=n
                          1+i.   NB. 1..n
                    2&|0&,   NB. prepend 0, but only if n is odd
  (       ]    "0|.)   NB. for each pair (x,y) of the above and above reversed,
           #~@,        NB. concatenate x copies of x and y copies of y
    -:@#{.   NB. take half the rows
10 |         NB. modulo 10 to all elements of the array
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 16 bytes
```
←½Ṡz+↔↓¬%2¹m´Rŀ→
```
[Try it online!](https://tio.run/##ASkA1v9odXNr///ihpDCveG5oHor4oaU4oaTwqwlMsK5bcK0UsWA4oaS////Nw "Husk – Try It Online")
[Answer]
# [Icon](https://github.com/gtownsend/icon), 76 bytes
```
procedure f(n)
c:=seq(1-n%2)&write(repl(n%10,n)||repl(c%10,c))&(n-:=1)=c
end
```
[Try it online!](https://tio.run/##Zc9NCoMwEAXgvacIgjIDFTL1ZxHITbopY4RAO9rY0o13t9pubDK79/h4MJ5HWdcpjOz6V3BqAMGMjZ3dA6iS4ozlO/ing@CmG0hB@iS4LN/Ee2LEEqQyltBy5qQ/jN2vXgAztd1vJK@VyY/FADX@gYs0CWli0iakjUmXkC4mpGNCOjGUGNrM/uYH "Icon – Try It Online")
Inspired by [xnor's Python solution](https://codegolf.stackexchange.com/a/203140/75681) - don't forget to upvote it!
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 106 bytes
```
(r=#+(y=Mod[#+1,2]);""<>{z@#,z[r-#]}&/@Range@r)[[-⌈r/2⌉;;-y-1]]&
z@x_:=""<>ToString/@Table[x~Mod~10,x]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X6PIVllbo9LWNz8lWlnbUMcoVtNaScnGrrrKQVmnKrpIVzm2Vk3fISgxLz3VoUgzOlr3UU9Hkb7Ro55Oa2vdSl3D2Fg1riqHingrW5C2kPzgkqLMvHR9h5DEpJzU6Io6oMF1hgY6FbH/ISLVAUD5En2HtOjsWB0w20FJqVanOlvHWMfQoDb2/38A "Wolfram Language (Mathematica) – Try It Online")
]