1
- import { getPuzzle } from "../../utils" ;
1
+ import { timePart1 , timePart2 } from "../../utils/time-part " ;
2
2
3
- const puzzleInput = getPuzzle ( __dirname ) . trim ( ) ;
4
- const diskMap = puzzleInput . split ( "" ) ;
3
+ const parseInput = ( input : string ) => input . split ( "" ) ;
5
4
6
5
// Part 1
7
- ( ( ) => {
8
- console . time ( "part 1" ) ;
6
+ export const part1 = timePart1 ( ( input : string ) => {
7
+ const diskMap = parseInput ( input ) ;
9
8
let representation = "" ;
10
9
11
10
for ( let i = 0 ; i < diskMap . length ; i ++ ) {
@@ -26,7 +25,7 @@ const diskMap = puzzleInput.split("");
26
25
let lastFileBlockIndex = representationArr . findLastIndex ( ( e ) => e !== "." ) ;
27
26
28
27
while ( lastFileBlockIndex > firstFreeSpaceBlockIndex ) {
29
- const lastEntry = representationArr . pop ( ) ;
28
+ const lastEntry = representationArr . pop ( ) ! ;
30
29
31
30
if ( lastEntry !== "." ) {
32
31
representationArr [ firstFreeSpaceBlockIndex ] = lastEntry ;
@@ -50,13 +49,11 @@ const diskMap = puzzleInput.split("");
50
49
}
51
50
}
52
51
53
- console . log ( "part 1 checksum ::" , checksum ) ;
54
- console . timeEnd ( "part 1" ) ;
55
- } ) ( ) ;
52
+ return checksum ;
53
+ } ) ;
56
54
57
- // Part 2
58
- ( ( ) => {
59
- console . time ( "part 2" ) ;
55
+ export const part2 = timePart2 ( ( input : string ) => {
56
+ const diskMap = parseInput ( input ) ;
60
57
let representation = "" ;
61
58
62
59
for ( let i = 0 ; i < diskMap . length ; i ++ ) {
@@ -145,6 +142,5 @@ const diskMap = puzzleInput.split("");
145
142
}
146
143
}
147
144
148
- console . log ( "part 2 checksum ::" , checksum ) ;
149
- console . timeEnd ( "part 2" ) ;
150
- } ) ( ) ;
145
+ return checksum ;
146
+ } ) ;
0 commit comments