| 17 | ) |
| 18 | |
| 19 | func Problem15(gridSize int) int { |
| 20 | /** |
| 21 | Author note: |
| 22 | We can solve this problem using combinatorics. |
| 23 | Here is a good blog post that explains the solution: |
| 24 | |
| 25 | [link](https://stemhash.com/counting-lattice-paths/) |
| 26 | |
| 27 | Btw, I'm not related to the author of the blog post. |
| 28 | |
| 29 | After some simplification, we can see that the solution is: |
| 30 | (2n)! / (n!)^2 |
| 31 | |
| 32 | We can use the factorial package to calculate the factorials. |
| 33 | */ |
| 34 | |
| 35 | n := gridSize |
| 36 | |
| 37 | numerator, _ := factorial.Iterative(2 * n) |
| 38 | denominator, _ := factorial.Iterative(n) |
| 39 | denominator *= denominator |
| 40 | |
| 41 | return numerator / denominator |
| 42 | } |