-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.ts
44 lines (37 loc) · 1002 Bytes
/
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
import type { Day } from './Day.ts';
export class DayImpl implements Day {
private readonly input: string[];
constructor(input: string) {
this.input = this.parseInput(input);
}
parseInput(input: string) {
return input
.trim()
.split('\n\n');
}
partOne() {
const keys: number[][] = this.input.filter(block => block.startsWith('.')).map(toPins);
const locks: number[][] = this.input.filter(block => block.startsWith('#')).map(toPins);
return keys
.map((key) => {
return locks
.filter(lock => !lock.some((x, i) => x + key[i] > 7))
.length;
})
.reduce((sum, val) => sum + val, 0);
}
partTwo() {
}
}
function toPins(block: string): number[] {
return block
.split('\n')
.map((line: string) => {
return line
.split('')
.map((char: string): number => {
return char === '#' ? 1 : 0;
});
})
.reduce((total, row) => total.map((x, i) => x + row[i]));
}