diff --git a/DIRECTORY.md b/DIRECTORY.md index 6c1fa7aeb8..7f6484cae5 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -35,6 +35,8 @@ * [ROT13](Ciphers/ROT13.js) * [VigenereCipher](Ciphers/VigenereCipher.js) * [XORCipher](Ciphers/XORCipher.js) +* **Compression** + * [RLE](Compression/RLE.js) * **Conversions** * [ArbitraryBase](Conversions/ArbitraryBase.js) * [ArrayBufferToBase64](Conversions/ArrayBufferToBase64.js) @@ -285,6 +287,7 @@ * [Problem016](Project-Euler/Problem016.js) * [Problem017](Project-Euler/Problem017.js) * [Problem018](Project-Euler/Problem018.js) + * [Problem019](Project-Euler/Problem019.js) * [Problem020](Project-Euler/Problem020.js) * [Problem021](Project-Euler/Problem021.js) * [Problem023](Project-Euler/Problem023.js) diff --git a/Project-Euler/Problem015.js b/Project-Euler/Problem015.js index 9e63c75705..67df9a438b 100644 --- a/Project-Euler/Problem015.js +++ b/Project-Euler/Problem015.js @@ -7,8 +7,8 @@ How many such routes are there through a 20×20 grid? // A lattice path is composed of horizontal and vertical lines that pass through lattice points. export const latticePath = (gridSize) => { - let paths - for (let i = 1, paths = 1; i <= gridSize; i++) { + let paths = 1 + for (let i = 1; i <= gridSize; i++) { paths = (paths * (gridSize + i)) / i } // The total number of paths can be found using the binomial coefficient (b+a)/a. diff --git a/Project-Euler/test/Problem015.test.js b/Project-Euler/test/Problem015.test.js new file mode 100644 index 0000000000..c5e7484df8 --- /dev/null +++ b/Project-Euler/test/Problem015.test.js @@ -0,0 +1,14 @@ +import { expect } from 'vitest' +import { latticePath } from '../Problem015' + +describe('Finding total numbers of Lattice Paths', () => { + test.each([ + [2, 6], + [4, 70], + [5, 252], + [10, 184756], + [20, 137846528820] + ])('If Grid Size: %i, then Lattice Paths count: %i', (a, expected) => { + expect(latticePath(a)).toBe(expected) + }) +})
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: