This commit is contained in:
2020-12-06 12:00:47 +00:00
parent 5557eb57e2
commit d97cf9f03a
3 changed files with 2200 additions and 0 deletions

2176
06/input Normal file

File diff suppressed because it is too large Load Diff

6
06/part1.js Normal file
View File

@@ -0,0 +1,6 @@
const fs = require('fs');
fs.readFile('input', (err, data) => {
if (err) throw err;
let groups = data.toString().split("\n\n").map( (group) => new Set( group.replace(/\r?\n|\r/g, "").split('') ) );
console.log(groups.reduce((sum, group) => sum + group.size, 0));
});

18
06/part2.js Normal file
View File

@@ -0,0 +1,18 @@
const fs = require('fs');
Set.prototype.intersect = function(other) {
let out = new Set();
other.forEach((entry) => { this.has(entry) && out.add(entry) });
return out;
}
fs.readFile('input', (err, data) => {
if (err) throw err;
let groups = data.toString().split("\n\n").map((group) => {
let people = group.trim().split("\n").map((person) => new Set(person.trim().split("")));
return people.reduce((sum,person) => sum.intersect(person));
});
console.log( groups.reduce((sum, group) => sum + group.size, 0) );
});