feat(euler): 15 - Lattice paths

-
This commit is contained in:
newt 2024-10-09 18:02:38 +01:00
parent 2311009b87
commit e3b60cbc09
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,14 @@
// See https://github.com/newtykins/the-honk/tree/main/euler/thoughts/15%20-Lattice%20Paths.md
export {};
const factorial = (n: number) => {
if (n < 0) return -1;
else if (n === 0) return 1;
else return n * factorial(n - 1);
};
const countLatticePaths = (width: number, height: number) => {
return factorial(width + height) / (factorial(width) * factorial(height));
};
console.log(countLatticePaths(20, 20));

View file

@ -0,0 +1,9 @@
For a lattice with dimensions m x n, all paths will have m + n segments. m segments go down, n segments go right. To count m + n slots, count the ways to pick m downward moves - the rest will be rightward moves.
![](assets/15.svg)
### LaTeX
```
{m + n \choose m} = {m + n \choose n} = \frac{(m+n)!}{m!n!}
```