up to day 6
This commit is contained in:
40
2020/6.js
Normal file
40
2020/6.js
Normal 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}`);
|
||||
Reference in New Issue
Block a user