-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.ts
56 lines (53 loc) · 1.37 KB
/
03.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
48
49
50
51
52
53
54
55
56
import Solution from "./solution.ts";
const task = new Solution(
(arr: string[][]) =>
arr
.map((e) => {
const [left, right] = [
e.slice(0, e.length / 2),
e.slice(e.length / 2),
].map((m) => new Set(m));
const intersection = new Set<string>();
for (const char of left) {
if (right.has(char)) intersection.add(char);
}
let prio = 0;
for (const char of intersection) {
const code = char.charCodeAt(0);
if (code < 96) {
prio += code - 64 + 26;
} else {
prio += code - 96;
}
}
return prio;
})
.reduce((p, c) => p + c, 0),
(arr: string[][]) => {
let prio = 0;
while (arr.length > 0) {
const [f, s, t] = arr.slice(0, 3).map((m) => new Set(m));
const intersection = new Set<string>();
for (const char of f) {
if (s.has(char) && t.has(char)) intersection.add(char);
}
for (const char of intersection) {
const code = char.charCodeAt(0);
if (code < 96) {
prio += code - 64 + 26;
} else {
prio += code - 96;
}
}
arr = arr.slice(3);
}
return prio;
},
{
transform: (e) => e.split(""),
sep: "\n",
},
);
task.expect(157, 70);
if (import.meta.main) await task.execute();
export default task;