feat(euler): 15 - Lattice paths
-
This commit is contained in:
parent
2311009b87
commit
e3b60cbc09
2 changed files with 23 additions and 0 deletions
14
euler/src/15 - Lattice paths.ts
Normal file
14
euler/src/15 - Lattice paths.ts
Normal 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));
|
9
euler/thoughts/15 - Lattice paths.md
Normal file
9
euler/thoughts/15 - Lattice paths.md
Normal 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!}
|
||||
```
|
Loading…
Reference in a new issue