MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Problem15

Function Problem15

project_euler/problem_15/problem15.go:19–42  ·  view source on GitHub ↗
(gridSize int)

Source from the content-addressed store, hash-verified

17)
18
19func 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}

Callers 2

TestProblem15_FuncFunction · 0.85
BenchmarkProblem15_FuncFunction · 0.85

Calls 1

IterativeFunction · 0.92

Tested by 2

TestProblem15_FuncFunction · 0.68
BenchmarkProblem15_FuncFunction · 0.68