Skip to content

Commit 8af25f1

Browse files
authored
chore: Merge pull request #631 from anna-vodimed/master
Add solution for Project-Euler Problem15
2 parents 6e7d320 + b35104a commit 8af25f1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Project-Euler/Problem015.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// https://projecteuler.net/problem=15
2+
/* Starting in the top left corner of a 2×2 grid, and only being able to move to
3+
the right and down, there are exactly 6 routes to the bottom right corner.
4+
How many such routes are there through a 20×20 grid?
5+
*/
6+
7+
// A lattice path is composed of horizontal and vertical lines that pass through lattice points.
8+
9+
const latticePath = (gridSize) => {
10+
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.
15+
return paths
16+
}
17+
console.log(latticePath(20)) // output = 137846528820

0 commit comments

Comments
 (0)