2018-09-30 22:01:58 +00:00
---
id: 5900f37b1000cf542c50fe8e
title: 'Problem 15: Lattice paths'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 301780
2021-01-13 02:31:00 +00:00
dashedName: problem-15-lattice-paths
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2020-02-28 12:39:47 +00:00
2018-09-30 22:01:58 +00:00
Starting in the top left corner of a 2× 2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
2020-02-28 12:39:47 +00:00
< img class = "img-responsive center-block" alt = "a diagram of 6 2 by 2 grids showing all the routes to the bottom right corner" src = "https://cdn-media-1.freecodecamp.org/project-euler/1Atixoj.gif" style = "background-color: white; padding: 10px;" >
How many such routes are there through a given `gridSize` ?
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`latticePaths(4)` should return a number.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(typeof latticePaths(4) === 'number');
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`latticePaths(4)` should return 70.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert.strictEqual(latticePaths(4), 70);
```
`latticePaths(9)` should return 48620.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert.strictEqual(latticePaths(9), 48620);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
`latticePaths(20)` should return 137846528820.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert.strictEqual(latticePaths(20), 137846528820);
```
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
function latticePaths(gridSize) {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
latticePaths(4);
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
function latticePaths(gridSize) {
let paths = 1;
for (let i = 0; i < gridSize ; i + + ) {
paths *= (2 * gridSize) - i;
paths /= i + 1;
}
return paths;
}
```