Skip to content

Instantly share code, notes, and snippets.

@kimagure44
Created December 3, 2020 07:57
Show Gist options
  • Save kimagure44/4be7fb7743084f0645ffe15df3686445 to your computer and use it in GitHub Desktop.
Save kimagure44/4be7fb7743084f0645ffe15df3686445 to your computer and use it in GitHub Desktop.
Advent of code (2020) - CODE 3 - 1
(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