day 6 was ez

master
Jan 2020-12-06 17:54:51 +01:00
parent 19b9991276
commit c86f3fa478
3 changed files with 2201 additions and 0 deletions

2165
day_6/input.txt Normal file

File diff suppressed because it is too large Load Diff

17
day_6/task_1.js Normal file
View File

@ -0,0 +1,17 @@
const fs = require('fs');
const file = fs.readFileSync(__dirname + '/input.txt').toString('utf-8');
const groups = file.split('\n\n');
let total = 0;
groups.forEach(answers => {
answers = answers
.replace(/\n/g, '')
.split('');
let answered = {};
answers.forEach(a => answered[a] = true);
total += Object.keys(answered).length;
});
console.log(`Total: ${total}`);

19
day_6/task_2.js Normal file
View File

@ -0,0 +1,19 @@
const fs = require('fs');
const file = fs.readFileSync(__dirname + '/input.txt').toString('utf-8');
const groups = file.split('\n\n');
let total = 0;
groups.forEach(answers => {
answers = answers
.split('\n');
let answered = {};
answers.forEach( an => an.split('').forEach(a => answered[a] ? answered[a]++ : answered[a] = 1 ));
for (const [key, value] of Object.entries(answered)) {
if (value == answers.length) total++;
}
});
console.log(`Total: ${total}`);