Published
Edited
Dec 10, 2020
Insert cell
Insert cell
input = (await FileAttachment("Avent of Code 2020 - Day 06.txt").text())
.trim()
.split('\n\n')
.map(group => group.split('\n'))
Insert cell
answer1 = {
let sumCount = 0;

for (const group of input) {
let answers = new Set();
for (const person of group) {
for (const answer of person) answers.add(answer);
}
sumCount += answers.size;
}
return sumCount;
}
Insert cell
Insert cell
answer2 = {
let sumCount = 0;

for (const group of input) {
let answers = new Set();
for (const answer of group[0]) answers.add(answer);
for (let i = 1; i < group.length; i++) {
const person = group[i];
const sameAnswers = new Set();
for (const answer of person) {
if (answers.has(answer)) sameAnswers.add(answer);
}
answers = sameAnswers;
}
sumCount += answers.size;
}
return sumCount;
}
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more