up to day 6

This commit is contained in:
Benjamin Kyd
2020-12-07 23:33:38 +00:00
parent 77ecdee0f8
commit 07af8fa645
13 changed files with 4304 additions and 1132 deletions

40
2020/6.js Normal file
View File

@@ -0,0 +1,40 @@
const fs = require('fs');
const input = fs.readFileSync('6.txt').toString().split('\n\n');
let uniqueGroupAnswers = [];
for (let i of input)
uniqueGroupAnswers.push([... new Set(i.replace(/\n/g, '').split(''))]);
let total = 0;
for (let i of uniqueGroupAnswers)
total += i.length;
console.log(`Part 1, Sum of answer counts: ${total}`);
total = 0;
function invArrDiff(arr)
{
let seen = [];
for (str of arr)
{
str = str.split('');
for (i of str)
{
if (seen.includes(i))
seen.push(i);
}
}
return seen;
}
for (let i of input)
{
let group = i.split('\n');
for (j of group)
j.split('');
total += invArrDiff(group).length;
}
console.log(`Part 2, Sum of answer counts: ${total}`);