[Question]
  [
# Goal
The goal of this challenge is to produce a function of `n` which computes the number of ways to partition the `n X 1` grid into triangles where all of the vertices of the triangles are on grid points.
# Example
For example, there are 14 ways to partition the 2 x 1 grid, so `f(2) = 14` via the following partitions [![Partitions of 2 x 1](https://i.stack.imgur.com/YLap3.png)](https://i.stack.imgur.com/YLap3.png)
where the partitions have 2, 2, 2, 2, 4, and 2 distinct orientations respectively.
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code wins.
  
[Answer]
# [Haskell](https://www.haskell.org/), ~~60 55 54~~ 52 bytes
After a drawing and programming a lot of examples, it occured to me that this is the same as the problem of the rooks:
> 
> On a \$(n+1) \times (n+1)\$ chessboard, how many ways are there for a rook to go from \$(0,0)\$ to \$(n,n)\$ by just moving right \$+(1,0)\$ or up \$+(0,1)\$? 
> 
> 
> 
Basically you have the top and the bottom line of the \$1 \times n\$ grid. Now you have to fill in the non-horizontal line. Each triangle must have two non-horizontal lines. Whether one of its sides is part of the top or the bottom line corresponds to the direction and length you'd go in the rooks problem. This is [OEIS A051708](http://oeis.org/A051708). As an illustration of this correspondence consider following examples. Here the top line corresponds to up-moves, while the bottom line corresponds to right-moves.
![](https://i.stack.imgur.com/fUFRx.png)
Thanks @PeterTaylor for -6 bytes and @PostLeftGarfHunter for -2 bytes!
```
b 0=1
b 1=2
b n=div((10*n-6)*b(n-1)-9*(n-2)*b(n-2))n
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P0nBwNaQK0nB0NYISObZpmSWaWgYGmjl6ZppaiVp5OkaaupaagFpIwjXSFMz739uYmaegq1CQVFmXomCikJuYoFCkkK0oZ6eoUHsfwA "Haskell – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 42 bytes
```
0?0=1
a?b=sum[a?i+i?a|i<-[0..b-1]]
f n=n?n
```
[Try it online!](https://tio.run/##BcExDoAgDADAnVd0cDM0MLhJ@hDCUBKJjdAQ0c2/493J4zpqndORC94w5TDeFplkFeJPdhsdYrY@JVNAg5LOxqIQoN@iDyzQuEOB6BG3NH8 "Haskell – Try It Online")
A fairly direct implementation that recurses over 2 variables.
Here's how we can obtain this solution. Start with code implementing a direct recursive formula:
**54 bytes**
```
0%0=1
a%b=sum$map(a%)[0..b-1]++map(b%)[0..a-1]
f n=n%n
```
[Try it online!](https://tio.run/##JcqxCoAgEADQ3a@4QaGQRIdGvyQcTkiS9JCs77@M1sc7sJ97KcxWWe8Equj7U2XFNqGaN2tMXFzQ@oP4Aw4QCciTIq6YCTy0K9MNEkaDBJszZg38Ag "Haskell – Try It Online")
Using [flawr's rook move interpretation](https://codegolf.stackexchange.com/a/176651/20260) ,`a%b` is the number of paths that get the rook from `(a,b)` to `(0,0)`, using only moves the decrease a coordinate. The first move either decreases `a` or decreases `b`, keeping the other the same, hence the recursive formula.
**49 bytes**
```
a?b=sum$map(a%)[0..b-1]
0%0=1
a%b=a?b+b?a
f n=n%n
```
[Try it online!](https://tio.run/##DcuxCoAgEADQ3a@4QaGIRIfGww8RhxOSJD0k6/vN/b2L@n2WMga5iP2rslJbSK3eaB13G4RRBq0gFXGKLToSCRhZ8aiUGRDak/kFCTNCAm@1PsL4AQ "Haskell – Try It Online")
We can avoid the repetition in `map(a%)[0..b-1]++map(b%)[0..a-1]` by noting that the two halves are the same with `a` and `b` swapped. The auxiliary call `a?b` counts the paths where the first move decreases `a`, and so `b?a` counts those where the first move decreases `b`. These are in general different, and they add to `a%b`.
The summation in `a?b` can also be written as a list comprehension `a?b=sum[a%i|i<-[0..b-1]]`.
**42 bytes**
```
0?0=1
a?b=sum[a?i+i?a|i<-[0..b-1]]
f n=n?n
```
[Try it online!](https://tio.run/##BcExDoAgDADAnVd0cDM0MLhJ@hDCUBKJjdAQ0c2/493J4zpqndORC94w5TDeFplkFeJPdhsdYrY@JVNAg5LOxqIQoN@iDyzQuEOB6BG3NH8 "Haskell – Try It Online")
Finally, we get rid of `%` and just write the recursion in terms of `?` by replacing `a%i` with `a?i+i?a` in the recursive call.
The new base case causes this `?` to give outputs double that of the `?` in the 49-byte version, since with `0?0=1`, we would have `0%0=0?0+0?0=2`. This lets use define `f n=n?n` without the halving that we'd other need to do.
[Answer]
## CJam (24 bytes)
```
{2,*e!{e`0f=:(1b2\#}%1b}
```
[Online demo](http://cjam.aditsu.net/#code=8%2C%0A%0A%7B2%2C*e!%7Be%600f%3D%3A(1b2%5C%23%7D%251b%7D%0A%0A%25p)
This uses [Bubbler's approach](https://codegolf.stackexchange.com/a/176663/194) of summing over permutations of `n` 0s and `n` 1s.
### Dissection
```
{         e# Define a block
  2,*     e#   Given input n, create an array of n 0s and n 1s
  e!      e#   Generate all permutations of that array
  {       e#   Map:
    e`    e#     Run-length encode
    0f=:( e#     Extract just the lengths and decrement them
    1b    e#     Sum
    2\#   e#     Raise 2 to the power of that sum
  }%
  1b      e#  Sum the mapped values
}
```
---
## Alternative approach (28 bytes)
```
{_1aa{_2$,f{j}@@,f{j}+1b}2j}
```
[Online demo](http://cjam.aditsu.net/#code=8%2C%0A%0A%7B_1aa%7B_2%24%2Cf%7Bj%7D%40%40%2Cf%7Bj%7D%2B1b%7D2j%7D%0A%0A%25p)
### Dissection
The triangles all have one horizontal edge and two edges which link the horizontal lines. Label the non-horizontal edges by a tuple of their two x-coords and sort lexicographically. Then the first edge is `(0,0)`, the last edge is `(n,n)`, and two consecutive edges differ in precisely one of the two positions. This makes for a simple recursion, which I've implemented using the memoised recursion operator `j`:
```
{            e# Define a block
  _          e#   Duplicate the argument to get n n
  1aa        e#   Base case for recursion: 0 0 => 1
  {          e#   Recursive body taking args a b
    _2$,f{j} e#     Recurse on 0 b up to a-1 b
    @@,f{j}  e#     Recurse on a 0 up to a b-1
    +1b      e#     Combine and sum
  }2j        e#   Memoised recursion with 2 args
}
```
### Note
This is not the first time I've wanted `fj` to be supported in CJam. Here it would bring the score down to 24 bytes also. Perhaps I should try to write a patch...
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~44~~ 31 bytes
[crossed out 44 is still regular 44](https://codegolf.stackexchange.com/a/153011/17602)
```
Ｆ⊕θ«≔⟦⟧ηＦ⊕θ⊞ηΣ∨⁺ηＥυ§λκ¹⊞υη»Ｉ⊟⊟υ
```
[Try it online!](https://tio.run/##bYyxCsIwFEXn5ive@B7EQVen4tRBDDiKQ0ijKaZpm@SJIH57bOvqcC9cOPcYp6MZtC/lNkTAJphoexuybXEigreo6pS6e8DLVYKjvaj@coqTQyfhzD2eIirPaZlHPSJLqHMTWvtCL@FBRBK2c8@q9cU/70eo2IWMB50yqmFcw7SApezK5um/ "Charcoal – Try It Online") Explanation: Works by calculating the number of ways to partition a trapezium of opposite side lengths `m,n` into triangles which all lie on integer offsets. This is simply a general case of the rectangle of size `n` in the question. The number of partitions is given recursively as the sums of the numbers of partitions for all sides `m,0..n-1` and `n,0..m-1`. This is equivalent to generalised problem of the rooks, [OEIS A035002](http://oeis.org/A035002). The code simply calculates the number of partitions working from `0,0` up to `n,n` using the previously calculated values as it goes.
```
Ｆ⊕θ«
```
Loop over the rows `0..n`.
```
≔⟦⟧η
```
Start with an empty row.
```
Ｆ⊕θ
```
Loop over the columns in the row `0..n`.
```
⊞ηΣ∨⁺ηＥυ§λκ¹
```
Take the row so far and the values in the previous rows at the current column, and add the sum total to the current row. However, if there are no values at all, then substitute `1` in place of the sum.
```
⊞υη»
```
Add the finished row to the list of rows so far.
```
Ｉ⊟⊟υ
```
Output the final value calculated.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~15~~ 14 bytes
```
Ø.xŒ!QŒɠ€’§2*S
```
[Try it online!](https://tio.run/##y0rNyan8///wDL2Ko5MUA49OOrngUdOaRw0zDy030gr@f7gdyPv/3xQA "Jelly – Try It Online")
-1 byte based on Peter Taylor's comment.
Uses [flawr's illustration](https://codegolf.stackexchange.com/a/176651/78410) directly, instead of the resulting formula.
### How it works
```
Ø.xŒ!QŒɠ€’§2*S    Main link (monad). Input: positive integer N.
Ø.x               Make an array containing N zeros and ones
   Œ!Q            All unique permutations
      Œɠ€         Run-length encode on each permutation
         ’§       Decrement and sum each
           2*S    Raise to power of 2 and sum
```
Take every possible route on a square grid. The number of ways to move L units in one direction as a rook is `2**(L-1)`. Apply this to every route and sum the number of ways to traverse each route.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 13 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
·LÉœÙεÅγo;P}O
```
Port of [*@Bubbler*'s Jelly answer](https://codegolf.stackexchange.com/a/176663/52210).
Very slow due to the permutations builtin.
[Try it online](https://tio.run/##AR8A4P9vc2FiaWX//8K3TMOJxZPDmc61w4XOs287UH1P//8z) or [verify the first four inputs](https://tio.run/##ASwA0/9vc2FiaWX/NEVOPyIgLT4gIj9ORP/Ct0zDicWTw5nOtcOFzrNvO1B9T/8s/w).
**Explanation:**
```
·                # Double the (implicit) input
 L               # Create a list in the range [1, doubled_input]
  É              # Check for each if they're odd (1 if truthy, 0 is falsey)
                 # We now have a list of n 0s and n 1s (n being the input)
   œ             # Get all permutations of that list
    Ù            # Only leave the unique permutations
     ε     }     # Map each permutation to:
      Åγ         #  Run-length encode the current value (short for `γ€g`)
        o        #  Take 2 to the power for each
         ;       #  Halve each
          P      #  Take the product of the mapped permutation
            O    # Sum all mapped values together (and output implicitly)
```
[Answer]
# JavaScript (ES6), ~~45 44~~ 42 bytes
Uses the recursive formula found by [Peter Taylor](https://codegolf.stackexchange.com/questions/176646/partitioning-the-grid-into-triangles/176652#176652) and [flawr](https://codegolf.stackexchange.com/questions/176646/partitioning-the-grid-into-triangles/176651#176651).
```
f=n=>n<2?n+1:(10-6/n)*f(--n)+9/~n*f(--n)*n
```
[Try it online!](https://tio.run/##LcoxDoJAEEbhq0xBMcNkgbUwUVi9ChtkjYb8Q8DYGL36SkH1vuI94zuuw/KYXw52G3NOAeGC7nCF@jP7xh1rSJnYOYie6h92l8jJFgYF8i2BOvLNVlWhwbDaNFaT3bmPXHzwlW3rSSkxRPIf "JavaScript (Node.js) – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 43 bytes
According to [OEIS](https://oeis.org/A051708), the generating function of this sequence is
$$\frac{1}{2}\left(\sqrt{\frac{1-x}{1-9x}}+1\right)$$
```
n->Vec(sqrt((1-x)/(1-9*x)+O(x^n++))+1)[n]/2
```
[Try it online!](https://tio.run/##K0gsytRNL/ifpmCr8D9P1y4sNVmjuLCoREPDULdCUx9IWmpVaGr7a1TE5Wlra2pqG2pG58XqG/1Pyy/SyANqMtBRMALigqLMvBKggJKCrh2QSNPI09TU/A8A "Pari/GP – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 51 bytes
```
lambda n:-~n*(n<2)or(10-6/n)*f(n-1)-(9-18/n)*f(n-2)
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSrcuT0sjz8ZIM79Iw9BA10w/T1MrTSNP11BTV8NS19ACxjfS/F9QlJlXohGdppGoqZCWX6SQqJCZp1CUmJeeqmGiGav5HwA "Python 3 – Try It Online")
Port of flawr's answer
]