Created
December 3, 2020 21:15
-
-
Save kimagure44/f03d8e21ddf786c7a8be1c163178e447 to your computer and use it in GitHub Desktop.
Advent of code (2020) - CODE 3 - 2
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
(async () => { | |
const fn = (right, down) => { | |
const rowLen = entries[0].length; | |
let movRight = 0; | |
let totalTree = 0; | |
console.log('---------------------------------'); | |
movRight = 0; | |
entries.forEach((row, index) => { | |
debugger; | |
if (index % down === 0) { | |
if (movRight >= rowLen) { | |
movRight = movRight - rowLen; | |
} | |
if (row[movRight] === '#') { | |
totalTree++; | |
} | |
console.log(row, row[movRight]); | |
movRight += right; | |
} | |
}); | |
console.log(`-------------- ${totalTree} ---------------`); | |
return totalTree; | |
} | |
const entries = (await(await fetch('https://adventofcode.com/2020/day/3/input')).text()).split('\n').filter(item => item || false); | |
const startTime = performance.now(); | |
const it1 = fn(1, 1); | |
const it2 = fn(3, 1); | |
const it3 = fn(5, 1); | |
const it4 = fn(7, 1); | |
const it5 = fn(1, 2); | |
console.log(it1, it2, it3, it4, it5) | |
const result = it1 * it2 * it3 * it4 * it5; | |
const endTime = performance.now(); | |
console.log(`Total árboles: ${result} ${parseFloat(endTime - startTime).toFixed(4)} ms`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment