-
Notifications
You must be signed in to change notification settings - Fork 0
/
day03_2.js
31 lines (30 loc) · 1 KB
/
day03_2.js
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
console.log("---");
import { readLines } from "https://deno.land/[email protected]/io/bufio.ts";
import { range } from "https://deno.land/x/[email protected]/range.mjs";
import { slidingWindows } from "https://deno.land/[email protected]/collections/mod.ts";
import count from "https://deno.land/x/[email protected]/src/collection/count.ts";
import { Arrays } from "https://deno.land/x/[email protected]/mod.ts";
const { chunk } = Arrays;
import {
intersection,
union,
difference,
} from "https://deno.land/x/set_operations/mod.ts";
const a = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const all = (await Deno.readTextFile("./resources/input03.txt"))
.trim()
.split("\n");
const toC = (c) => {
const n = a.indexOf(c);
return n;
};
const res = [];
for (let g of all.chunk(3)) {
console.log({ g });
const a1 = new Set(g[0]);
const a2 = new Set(g[1]);
const a3 = new Set(g[2]);
const i = [...intersection(a3, intersection(a1, a2))].map(toC);
res.push(...i);
}
console.log(res.reduce((acc, i) => i + acc, 0));