# How Many Ways Can You Tile the Tilted Square?

This is a problem that can be divided into subproblems. For example, if we decide to pick this rectangle:

There are four components this gets split into: a triangular formation on the top and bottom, and a single tile on the left and right.

Let's focus on the top component. This can be split in three ways:

- In the first, this is just a smaller subproblem: a triangular formation of height 2. Let's call this a corner triangle of height 2.
- In the second, this is two smaller subproblems, each of them being a triangle. However, these triangles are different: the edge squares lie along the "hypotenuses" of these triangles. Let's call each of these a side triangle of size 2.
- In the third, this is three smaller subproblems, each of them being singular squares (only one way to tile). Technically, the one on the top is a corner triangle of side 1, and the ones on the left and right are side triangles of side 1.

Notice that we can find the number of ways to tile any particular subsection, and the total number of ways to tile is the product for each of the subsections.

So with this, we can establish the three functions needed to determine the overall answer:

- one for the overall diamond (let $f(n)$ describe this for a diamond with $n$ squares along one edge)
- one for the corner triangle (let $g(n)$ describe this for a corner triangle with height $n$)
- one for the side triangle (let $h(n)$ describe this for a side triangle with size $n$)

### Side triangles

Define $h(0)=1$. Now for an side triangle of size $n$, we can split by a rectangle, creating one side triangle of size $k$ and the other of size $n-1-k$. As a result, the total number of distinct formations is the sum of all these from $k=0$ to $k=n-1$, or:

$h(n)=\sum_{k=0}^{n-1}{h(k)\cdot h(n-1-k)}$Note that $h(1)=1$, $h(2)=2$, and $h(3)=5$, which can be seen manually. In fact, these are Catalan numbers! $h(n)$ is indeed just the $n$–th Catalan number, which we will denote as $C_n$.

The first few Catalan numbers:

$n$ | 0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|---|

$C_n$ | 1 | 1 | 2 | 5 | 14 | 42 |

### Corner triangles

Define $g(0)=1$. Now for a corner triangle of height $n$, we can split by a rectangle, creating one corner triangle of size $k$ and two corner triangles, each of size $n-1-k$. So the total number of distinct formations is the sum of all these from $k=0$ to $k=n-1$, or:

$g(n)=\sum_{k=0}^{n-1}{g(k)\bigl(f(n-1-k)\bigl)^2} \\ g(n)=\sum_{k=0}^{n-1}{g(k)(C_{n-1-k})^2}$The first few values of $g(n)$:

$n$ | 0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|---|

$g(n)$ | 1 | 1 | 2 | 5 | 14 | 42 |

### Diamonds

For a diamond, after choosing a rectangle, we split into four corner triangle subregions: two of size $k$ and two of size $n-1-k$. So the total number of distinct formations is the sum of all these from $k=0$ to $k=n-1$, or:

$f(n)=\sum_{k=0}^{n-1}{\bigl(g(k)\bigl)^2\bigl(g(n-1-k)\bigl)^2}$The first few values of $f(n)$ (with $f(0)=1$):

$n$ | 0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|---|

$f(n)$ | 1 | 1 | 2 | 9 | 106 | 3002 |

The questions asked us about diamonds of sides of $n=4$ and $n=5$, leading us to the answers below!

## Answers

**This Week's Fiddler**: 106

**Extra Credit**: 3002

## And beyond

While I did not determine a closed form, we now have a recursive definition of the sequence! With $C_n=\frac{1}{n+1}{2n\choose n}$ as the $n$–th Catalan number, we can define the following functions to describe $f(n)$:

$g(0)=1, f(0)=1 \\ g(n)=\sum_{k=0}^{n-1}{g(k)(C_{n-1-k})^2} \\ f(n)=\sum_{k=0}^{n-1}{\bigl(g(k)\bigl)^2\bigl(g(n-1-k)\bigl)^2}$And the values for up to $n=20$:

$n$ | $C_n$ | $g(n)$ | $f(n)$ |
---|---|---|---|

0 | 1 | 1 | 1 |

1 | 1 | 1 | 1 |

2 | 2 | 2 | 2 |

3 | 5 | 7 | 9 |

4 | 14 | 38 | 106 |

5 | 42 | 274 | 3002 |

6 | 132 | 2350 | 153432 |

7 | 429 | 22531 | 11209105 |

8 | 1430 | 233292 | 1027079042 |

9 | 4862 | 2555658 | 109919229034 |

10 | 16796 | 29232554 | 13176445132632 |

11 | 58786 | 346013450 | 1722653938299826 |

12 | 208012 | 4211121946 | 241219579652401784 |

13 | 742900 | 52446977292 | 35714287018956797136 |

14 | 2674440 | 666024794758 | 5537912139464706335288 |

15 | 9694845 | 8599676755883 | 892837334232641551689441 |

16 | 35357670 | 112647192598844 | 148820403511450083446225026 |

17 | 129644790 | 1494224720878614 | 25530595384066080684214316346 |

18 | 477638700 | 20041069061550880 | 4491442427844125614764520894656 |

19 | 1767263190 | 271454315346852530 | 807865223153246598712705790433906 |

20 | 6564120420 | 3709291397981162290 | 148197637526550957704054952422581656 |