Created
December 4, 2020 19:36
-
-
Save iJustErikk/a0d6bf30c272d16c06dae4452db9218a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gridTraveler = (x, y, z, memo = new Map()) => { | |
const key = `${x},${y},${z}`; | |
if (memo.has(key)) return memo.get(key); | |
if (x === 0 || y === 0 || z === 0) return 0; | |
if (x === 1 && y === 1 && z === 1) return 1; | |
memo.set(key, gridTraveler(x - 1, y, z, memo) + gridTraveler(x, y - 1, z, memo)) + gridTraveler(x, y, z - 1, memo)); | |
return memo.get(key); | |
}; | |
console.log(gridTraveler(10, 10, 10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment