Skip to content

Commit 6bbe658

Browse files
committed
day 25, and with that all days are completed for 2024
1 parent 81c6fbc commit 6bbe658

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

.aoc_tiles/tiles/2024/25.png

9.21 KB
Loading

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- AOC TILES BEGIN -->
22
<h1 align="center">
3-
2024 - 48 ⭐ - TypeScript
3+
2024 - 50 ⭐ - TypeScript
44
</h1>
55
<a href="src/2024/day1.ts">
66
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
@@ -74,6 +74,9 @@
7474
<a href="src/2024/day24.ts">
7575
<img src=".aoc_tiles/tiles/2024/24.png" width="161px">
7676
</a>
77+
<a href="src/2024/day25.ts">
78+
<img src=".aoc_tiles/tiles/2024/25.png" width="161px">
79+
</a>
7780
<h1 align="center">
7881
2023 - 50 ⭐ - TypeScript
7982
</h1>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"lint": "prettier -w src/**/*.ts",
8-
"run": "tsc -p tsconfig.json && node build/day24.js"
8+
"run": "tsc -p tsconfig.json && node build/day25.js"
99
},
1010
"author": "",
1111
"license": "ISC",

src/2024/day25.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { input } from './input';
2+
3+
const groups = input.split('\n\n').map((lk) => lk.split('\n'));
4+
5+
let isLock: boolean = false;
6+
7+
const myLocks: number[][] = [];
8+
const myKeys: number[][] = [];
9+
10+
for (let g of groups) {
11+
isLock = g[0] === '#####';
12+
const rows = g.length;
13+
const cols = g[0].length;
14+
const map: number[] = new Array(cols).fill(0);
15+
16+
for (let j = 0; j < cols; j++) {
17+
for (let i = 0; i < rows; i++) {
18+
if (isLock && g[i][j] === '#') {
19+
map[j] = i;
20+
}
21+
if (!isLock && g[i][j] === '.') {
22+
map[j] = i;
23+
}
24+
}
25+
}
26+
isLock ? myLocks.push(map) : myKeys.push(map);
27+
}
28+
29+
function part1(keys: number[][], locks: number[][]) {
30+
let cnt = 0;
31+
32+
let fit = true;
33+
for (let key of keys) {
34+
for (let lock of locks) {
35+
fit = true;
36+
for (let i = 0; i < lock.length; i++) {
37+
if (key[i] < lock[i]) {
38+
fit = false;
39+
break;
40+
}
41+
}
42+
cnt += fit ? 1 : 0;
43+
}
44+
}
45+
46+
return cnt;
47+
}
48+
49+
console.log(part1(structuredClone(myKeys), structuredClone(myLocks)));

0 commit comments

Comments
 (0)