Created
December 3, 2020 07:57
-
-
Save kimagure44/4be7fb7743084f0645ffe15df3686445 to your computer and use it in GitHub Desktop.
Advent of code (2020) - CODE 3 - 1
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 result = []; | |
const entries = (await(await fetch('https://adventofcode.com/2020/day/3/input')).text()).split('\n').filter(item => item || false); | |
const startTime = performance.now(); | |
const rowLen = entries[0].length; | |
const incX = 3; | |
let movRight = 0; | |
let totalTree = 0; | |
entries.forEach((row, index) => { | |
if (movRight >= rowLen) { | |
movRight = movRight - rowLen; | |
} | |
console.log(row, row[movRight], movRight, rowLen); | |
if (row[movRight] === '#') { | |
totalTree++; | |
} | |
movRight += incX; | |
}); | |
const endTime = performance.now(); | |
console.log(`Arboles totales: ${totalTree} ${parseFloat(endTime - startTime).toFixed(4)} ms`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment