We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 22fcd2d commit b35104aCopy full SHA for b35104a
Project-Euler/Problem015.js
@@ -7,9 +7,11 @@ How many such routes are there through a 20×20 grid?
7
// A lattice path is composed of horizontal and vertical lines that pass through lattice points.
8
9
const latticePath = (gridSize) => {
10
- for (var i = 1, paths = 1; i <= gridSize; i++)
+ let paths
11
+ for (let i = 1, paths = 1; i <= gridSize; i++) {
12
+ paths = paths * (gridSize + i) / i
13
+ }
14
// The total number of paths can be found using the binomial coefficient (b+a)/a.
- { paths = paths * (gridSize + i) / i }
15
return paths
16
}
17
console.log(latticePath(20)) // output = 137846528820
0 commit comments