-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.ts
36 lines (25 loc) · 847 Bytes
/
day6.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetchInput } from "./common_ts/inputAccess.ts";
const input = await fetchInput(6);
const groups = input.split("\n\n");
//part1
let numberOfQuestions = 0;
for (let group of groups) {
const persons = group.split("\n");
const distinctQuestions = new Set(persons.flatMap((x) => [...x]));
numberOfQuestions += distinctQuestions.size;
}
//part2
let everyoneAnsweredYes = 0;
for (let group of groups) {
const people = group.split("\n");
const peopleAnswers = people.map(x => new Set([...x]))
const commonAnswers = []
peopleAnswers[0].forEach(answer => {
if(peopleAnswers.reduce((prev, cur) => prev && cur.has(answer), true))
commonAnswers.push(answer)
})
everyoneAnsweredYes += commonAnswers.length
// console.log(commonAnswers.size)
}
console.log(everyoneAnsweredYes)
// console.log(numberOfQuestions);