-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpart-one.js
34 lines (27 loc) · 991 Bytes
/
part-one.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs');
const path = require('path');
let raw_input = fs.readFileSync(path.resolve(__dirname, './input.txt'), 'utf8');
// Last filter is to remove any empty lines
let input = raw_input.split('\n').filter(n => n);
let two_multiplier = 0;
let three_multiplier = 0;
input.forEach(id => {
let letter_count_lookup = {};
id.split('').forEach(c => {
if (!letter_count_lookup[c]) {
letter_count_lookup[c] = 1;
} else {
letter_count_lookup[c]++;
}
});
let letter_count = Object.values(letter_count_lookup);
if (letter_count.includes(2)) {
two_multiplier++;
}
if (letter_count.includes(3)) {
three_multiplier++;
}
});
console.log(`Number of IDs with 2 repeated letters: ${two_multiplier}`);
console.log(`Number of IDs with 3 repeated letters: ${three_multiplier}`);
console.log(`Your checksum = ${two_multiplier} * ${three_multiplier} =\n\t${two_multiplier * three_multiplier}`);