-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
p1.ts
42 lines (38 loc) · 1.11 KB
/
p1.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
import { task } from '@alexaegis/advent-of-code-lib';
import { drawMapStatic, renderMatrix } from '@alexaegis/advent-of-code-lib/functions';
import { sum } from '@alexaegis/advent-of-code-lib/math';
import { GridGraph } from '@alexaegis/advent-of-code-lib/model';
import packageJson from '../package.json';
import { Tile, computeMap, type Vacuum } from './parse.js';
const W = 50;
const H = 50;
export const draw = (m: Map<string, Tile>, vacuum: Vacuum): void => {
const mat = drawMapStatic(
m,
(t) => {
switch (t) {
case Tile.SCAFFOLD: {
return '##';
}
default: {
return ' ';
}
}
},
0,
W,
0,
H,
false,
true,
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
mat[vacuum.pos.y + 1]![vacuum.pos.x + 1] = vacuum.dir.reverse('v').marker + '!';
console.log(renderMatrix(mat, true, false));
};
export const p1 = (input: string): number =>
GridGraph.fromMap(computeMap(input)[0])
.getIntersections((n) => n?.value === Tile.SCAFFOLD)
.map((i) => Math.abs(i.coordinate.x * i.coordinate.y))
.reduce(sum, 0);
await task(p1, packageJson.aoc); // 4864 ~42ms