Created
December 2, 2020 23:51
-
-
Save kimagure44/c3b3507aba93bb80952a66f25af30ba8 to your computer and use it in GitHub Desktop.
Advent of code (2020) - CODE 2 - 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 result = []; | |
const entries = (await(await fetch('https://adventofcode.com/2020/day/2/input')).text()).split('\n').filter(item => item || false).map(item => item.split(':')); | |
const startTime = performance.now(); | |
let totalCorrectPassword = 0; | |
entries.forEach((item, index, arr) => { | |
const [range, letter] = item[0].split(' '); | |
const [ first, second ] = range.split('-'); | |
const password = item[1].trim(); | |
const checkPassword = new String(password); | |
if (checkPassword[first - 1] === letter && checkPassword[second - 1] !== letter || checkPassword[first - 1] !== letter && checkPassword[second - 1] === letter) { | |
totalCorrectPassword++; | |
console.log(`Letter ${letter} => first: ${first} / second: ${second} / password: ${password} / First: ${checkPassword[first - 1]} / Second: ${checkPassword[second - 1]}`); | |
} | |
}); | |
const endTime = performance.now(); | |
console.log(`Total correct passwords: ${totalCorrectPassword}`); | |
console.log(result); | |
console.log(`${parseFloat(endTime - startTime).toFixed(4)} ms`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment