Day 6
This commit is contained in:
6
06/part1.js
Normal file
6
06/part1.js
Normal 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
18
06/part2.js
Normal 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) );
|
||||
});
|
Reference in New Issue
Block a user