Thanks to visit codestin.com Credit goes to github.com
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.
anna-vodimed/master
2 parents 6e7d320 + b35104a commit 8af25f1Copy full SHA for 8af25f1
1 file changed
Project-Euler/Problem015.js
@@ -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