-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.ts
49 lines (40 loc) · 1.02 KB
/
day25.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
import { input } from './input';
const groups = input.split('\n\n').map((lk) => lk.split('\n'));
let isLock: boolean = false;
const myLocks: number[][] = [];
const myKeys: number[][] = [];
for (let g of groups) {
isLock = g[0] === '#####';
const rows = g.length;
const cols = g[0].length;
const map: number[] = new Array(cols).fill(0);
for (let j = 0; j < cols; j++) {
for (let i = 0; i < rows; i++) {
if (isLock && g[i][j] === '#') {
map[j] = i;
}
if (!isLock && g[i][j] === '.') {
map[j] = i;
}
}
}
isLock ? myLocks.push(map) : myKeys.push(map);
}
function part1(keys: number[][], locks: number[][]) {
let cnt = 0;
let fit = true;
for (let key of keys) {
for (let lock of locks) {
fit = true;
for (let i = 0; i < lock.length; i++) {
if (key[i] < lock[i]) {
fit = false;
break;
}
}
cnt += fit ? 1 : 0;
}
}
return cnt;
}
console.log(part1(structuredClone(myKeys), structuredClone(myLocks)));