Files
freeCodeCamp/curriculum/challenges/espanol/10-coding-interview-prep/project-euler/problem-15-lattice-paths.md
2022-09-27 10:30:30 +02:00

1.4 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5900f37b1000cf542c50fe8e Problema 15: Trayectorias en una cuadrícula 1 301780 problem-15-lattice-paths

--description--

Comenzando en la esquina superior izquierda de una cuadrícula 2x2, y estando permitido solo moverse hacia la izquierda y hacia abajo, hay exactamente 6 trayectorias para alcanzar la esquina inferior derecha.

un diagrama de 6 cuadrículas de 2x2 mostrando todas las trayectorias hacia la esquina inferior derecha

¿Cuántas trayectorias de este tipo hay en una cuadrícula de gridSize (tamaño) dado?

--hints--

latticePaths(4) debe devolver un número.

assert(typeof latticePaths(4) === 'number');

latticePaths(4) debe devolver 70.

assert.strictEqual(latticePaths(4), 70);

latticePaths(9) debe devolver 48620.

assert.strictEqual(latticePaths(9), 48620);

latticePaths(20) debe devolver 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;
}