Skip to content

Commit 096e624

Browse files
📦 NEW: Added test cases for Project Euler Problem 15 and a minor bug fix to the solution
1 parent 944077b commit 096e624

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: ‎Project-Euler/Problem015.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ How many such routes are there through a 20×20 grid?
77
// A lattice path is composed of horizontal and vertical lines that pass through lattice points.
88

99
export const latticePath = (gridSize) => {
10-
let paths
11-
for (let i = 1, paths = 1; i <= gridSize; i++) {
10+
let paths = 1
11+
for (let i = 1; i <= gridSize; i++) {
1212
paths = (paths * (gridSize + i)) / i
1313
}
1414
// The total number of paths can be found using the binomial coefficient (b+a)/a.

Diff for: ‎Project-Euler/test/Problem015.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from 'vitest'
2+
import { latticePath } from '../Problem015'
3+
4+
describe('Finding total numbers of Latice Paths', () => {
5+
test.each([
6+
[2, 6],
7+
[4, 70],
8+
[10, 184756],
9+
[20, 137846528820]
10+
])('If Grid Size: %i, then Latice Paths count: %i', (a, expected) => {
11+
expect(latticePath(a)).toBe(expected)
12+
})
13+
})

0 commit comments

Comments
 (0)