Skip to content

Commit b941672

Browse files
update problem15
1 parent db38314 commit b941672

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Project-Euler/Problem015.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ the right and down, there are exactly 6 routes to the bottom right corner.
44
How many such routes are there through a 20×20 grid?
55
*/
66

7-
const latticePath = n => {
7+
//A lattice path is composed of horizontal and vertical lines that pass through lattice points.
88

9-
for (var i = 1, c = 1; i <= n; i++)
10-
c = c * (n + i) / i;
11-
return c;
9+
const latticePath = (gridSize) => {
10+
11+
for (var i = 1, paths = 1; i <= gridSize; i++)
12+
//The total number of paths can be found using the binomial coefficient (b+a)/a.
13+
paths = paths * (gridSize + i) / i;
14+
return paths;
1215
}
13-
console.log(latticePath(20));
16+
console.log(latticePath(20)); //output = 137846528820

0 commit comments

Comments
 (0)