1.4 KiB
1.4 KiB
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5900f37b1000cf542c50fe8e | Problema 15: Percorsi nel reticolo | 1 | 301780 | problem-15-lattice-paths |
--description--
Iniziando nell'angolo in alto a sinistra di una griglia 2x2, e avendo l'abilità di muoversi solo verso destra e verso il basso, ci sono esattamente 6 strade verso l'angolo in basso a sinistra.
Quante strade di questo tipo ci sono data la dimensione della griglia gridSize
?
--hints--
latticePaths(4)
dovrebbe restituire un numero.
assert(typeof latticePaths(4) === 'number');
latticePaths(4)
dovrebbe restituire 70.
assert.strictEqual(latticePaths(4), 70);
latticePaths(9)
dovrebbe restituire 48620.
assert.strictEqual(latticePaths(9), 48620);
latticePaths(20)
dovrebbe restituire 137846528820.
assert.strictEqual(latticePaths(20), 137846528820);
--seed--
--seed-contents--
function latticePaths(gridSize) {
return true;
}
latticePaths(4);
--solutions--
function latticePaths(gridSize) {
let paths = 1;
for (let i = 0; i < gridSize; i++) {
paths *= (2 * gridSize) - i;
paths /= i + 1;
}
return paths;
}