1- import { getPuzzle } from "../../utils" ;
1+ import { timePart1 , timePart2 } from "../../utils/time-part " ;
22
3- const puzzleInput = getPuzzle ( __dirname ) . trim ( ) ;
4- const diskMap = puzzleInput . split ( "" ) ;
3+ const parseInput = ( input : string ) => input . split ( "" ) ;
54
65// Part 1
7- ( ( ) => {
8- console . time ( "part 1" ) ;
6+ export const part1 = timePart1 ( ( input : string ) => {
7+ const diskMap = parseInput ( input ) ;
98 let representation = "" ;
109
1110 for ( let i = 0 ; i < diskMap . length ; i ++ ) {
@@ -26,7 +25,7 @@ const diskMap = puzzleInput.split("");
2625 let lastFileBlockIndex = representationArr . findLastIndex ( ( e ) => e !== "." ) ;
2726
2827 while ( lastFileBlockIndex > firstFreeSpaceBlockIndex ) {
29- const lastEntry = representationArr . pop ( ) ;
28+ const lastEntry = representationArr . pop ( ) ! ;
3029
3130 if ( lastEntry !== "." ) {
3231 representationArr [ firstFreeSpaceBlockIndex ] = lastEntry ;
@@ -50,13 +49,11 @@ const diskMap = puzzleInput.split("");
5049 }
5150 }
5251
53- console . log ( "part 1 checksum ::" , checksum ) ;
54- console . timeEnd ( "part 1" ) ;
55- } ) ( ) ;
52+ return checksum ;
53+ } ) ;
5654
57- // Part 2
58- ( ( ) => {
59- console . time ( "part 2" ) ;
55+ export const part2 = timePart2 ( ( input : string ) => {
56+ const diskMap = parseInput ( input ) ;
6057 let representation = "" ;
6158
6259 for ( let i = 0 ; i < diskMap . length ; i ++ ) {
@@ -145,6 +142,5 @@ const diskMap = puzzleInput.split("");
145142 }
146143 }
147144
148- console . log ( "part 2 checksum ::" , checksum ) ;
149- console . timeEnd ( "part 2" ) ;
150- } ) ( ) ;
145+ return checksum ;
146+ } ) ;
0 commit comments