-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
47 lines (38 loc) · 1.03 KB
/
mod.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
37
38
39
40
41
42
43
44
45
46
47
import { data } from "./data.ts";
const input: string[][] = data.split("\n\n").map((entry) =>
entry.replace(/\n/g, " ").split(" ")
);
const total: number = input.reduce((total, group) => {
const checker: string[] = [];
for (const str of group) {
str.split("").forEach((l) => {
if (!checker.includes(l)) checker.push(l);
});
}
return total + checker.length;
}, 0);
const partTwo = input.map((group) => {
let checker: { [key: string]: number } = {};
let total = 0;
group.forEach((person) => {
person.split("").forEach((selection) => {
if (!checker.hasOwnProperty(selection)) {
checker = {
...checker,
[selection]: 1,
};
} else {
checker[selection] += 1;
}
});
});
for (const key in checker) {
if (checker[key] === group.length) total += 1;
}
return total;
});
console.log(`[Part 1] What is the sum of those counts?`, total);
console.log(
`[Part 2] What is the sum of those counts?`,
partTwo.reduce((sum, cur) => sum + cur),
);