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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more