diff --git a/euler/src/15 - Lattice paths.ts b/euler/src/15 - Lattice paths.ts new file mode 100644 index 0000000..9ff61e2 --- /dev/null +++ b/euler/src/15 - Lattice paths.ts @@ -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)); diff --git a/euler/thoughts/15 - Lattice paths.md b/euler/thoughts/15 - Lattice paths.md new file mode 100644 index 0000000..98fe247 --- /dev/null +++ b/euler/thoughts/15 - Lattice paths.md @@ -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!} +```