File tree 4 files changed +54
-2
lines changed
4 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 1
1
<!-- AOC TILES BEGIN -->
2
2
<h1 align =" center " >
3
- 2024 - 48 ⭐ - TypeScript
3
+ 2024 - 50 ⭐ - TypeScript
4
4
</h1 >
5
5
<a href =" src/2024/day1.ts " >
6
6
<img src =" .aoc_tiles/tiles/2024/01.png " width =" 161px " >
74
74
<a href =" src/2024/day24.ts " >
75
75
<img src =" .aoc_tiles/tiles/2024/24.png " width =" 161px " >
76
76
</a >
77
+ <a href =" src/2024/day25.ts " >
78
+ <img src =" .aoc_tiles/tiles/2024/25.png " width =" 161px " >
79
+ </a >
77
80
<h1 align =" center " >
78
81
2023 - 50 ⭐ - TypeScript
79
82
</h1 >
Original file line number Diff line number Diff line change 5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
7
"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"
9
9
},
10
10
"author" : " " ,
11
11
"license" : " ISC" ,
Original file line number Diff line number Diff line change
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 ) ) ) ;
You can’t perform that action at this time.
0 commit comments