-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday03_1.js
39 lines (38 loc) · 1.02 KB
/
day03_1.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
32
33
34
35
36
37
38
39
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";
const sumR = (acc, i) => i + acc;
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");
console.log({ all });
const toC = (c) => {
const n = a.indexOf(c);
return n;
};
const res = [];
for (let line of all) {
console.log({ line });
const p1 = new Set(
line
.slice(0, line.length / 2)
.split("")
.map(toC)
);
const p2 = new Set(
line
.slice(line.length / 2)
.split("")
.map(toC)
);
res.push(...intersection(p1, p2));
}
console.log(res.reduce(sumR, 0));