This commit is contained in:
Jan 2020-12-02 17:29:13 +01:00
parent 1d00f7c69e
commit 44376bf893
3 changed files with 1057 additions and 0 deletions

1000
day_2/input.txt Normal file

File diff suppressed because it is too large Load diff

31
day_2/task_1.js Normal file
View file

@ -0,0 +1,31 @@
const fs = require('fs');
const file = fs.readFileSync('./input.txt').toString('utf-8');
const arr = file.split('\n');
let invalid = []
arr.forEach(item => {
// Split the puzzle input
let split = item.split(": ");
let pw = split[1];
split = split[0].split(" ");
let wantedLetter = split[1];
split = split[0].split("-");
let [lowerNum, upperNum] = split;
// Check if the password is valid
let count = 0;
for (let letter of pw) {
if (letter == wantedLetter) count++;
}
if (count < lowerNum || count > upperNum) {
invalid.push(pw);
}
});
console.log(`Total: ${arr.length}`);
console.log(`Invalid: ${invalid.length}`);
console.log(`Valid: ${arr.length - invalid.length}`);

26
day_2/task_2.js Normal file
View file

@ -0,0 +1,26 @@
const fs = require('fs');
const file = fs.readFileSync('./input.txt').toString('utf-8');
const arr = file.split('\n');
let invalid = []
arr.forEach(item => {
// Split the puzzle input
let split = item.split(": ");
let pw = split[1];
split = split[0].split(" ");
let wantedLetter = split[1];
split = split[0].split("-");
let [firstPos, secondPos] = split;
// Check if the password is valid
if (!(pw.charAt(Number(firstPos) - 1) == wantedLetter ^ pw.charAt(Number(secondPos) - 1) == wantedLetter)) {
invalid.push(pw);
}
});
console.log(`Total: ${arr.length}`);
console.log(`Invalid: ${invalid.length}`);
console.log(`Valid: ${arr.length - invalid.length}`);