day 6 was ez
This commit is contained in:
parent
19b9991276
commit
c86f3fa478
2165
day_6/input.txt
Normal file
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
17
day_6/task_1.js
Normal 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
19
day_6/task_2.js
Normal 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}`);
|
Loading…
Reference in a new issue