2020-12-06 14:04:44 +01:00
|
|
|
#!/bin/node
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
fs.readFile('input.txt', (err, data) => {
|
|
|
|
const groups = data.toString()
|
|
|
|
.split('\n\n')
|
|
|
|
.map(group => group.split('\n')
|
|
|
|
.filter(person => person.length > 0));
|
|
|
|
|
|
|
|
let q1 = 0;
|
|
|
|
let q2 = 0;
|
|
|
|
for (const group of groups) {
|
|
|
|
let q1Questions = [];
|
|
|
|
let q2Questions = [];
|
|
|
|
|
|
|
|
for (const person of group) {
|
|
|
|
for (const question of person) {
|
|
|
|
if (q1Questions.indexOf(question) < 0) {
|
|
|
|
q1Questions.push(question);
|
2020-12-06 14:07:13 +01:00
|
|
|
}
|
2020-12-06 14:04:44 +01:00
|
|
|
|
2020-12-06 14:07:13 +01:00
|
|
|
if (q2Questions.indexOf(question) < 0 && group.every(person => person.indexOf(question) >= 0)) {
|
|
|
|
q2Questions.push(question);
|
2020-12-06 14:04:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q1 += q1Questions.length;
|
|
|
|
q2 += q2Questions.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(q1, q2);
|
|
|
|
});
|