@@ -3,22 +3,33 @@ let items;
3
3
4
4
fs . readFile ( './input.txt' , 'utf-8' , ( e , data ) => {
5
5
items = data . split ( "\n" ) ;
6
- const result = progress ( 0 , 0 , 0 ) ;
7
- console . log ( 'result!' , result ) ;
6
+ const resultPart1 = progress ( 0 , 0 , 0 , [ 3 , 1 ] ) ;
7
+ const resultPart2 = checkPart2 ( ) ;
8
+
9
+ console . log ( 'result!' , resultPart1 , resultPart2 ) ;
8
10
} ) ;
9
11
10
- function progress ( trees , currentRow , currentColumn ) {
12
+ function checkPart2 ( ) {
13
+ const oneone = progress ( 0 , 0 , 0 , [ 1 , 1 ] ) ;
14
+ const threeone = progress ( 0 , 0 , 0 , [ 3 , 1 ] ) ;
15
+ const fiveone = progress ( 0 , 0 , 0 , [ 5 , 1 ] ) ;
16
+ const sevenone = progress ( 0 , 0 , 0 , [ 7 , 1 ] ) ;
17
+ const onetwo = progress ( 0 , 0 , 0 , [ 1 , 2 ] ) ;
18
+ return oneone * threeone * fiveone * sevenone * onetwo ;
19
+ }
20
+
21
+ function progress ( trees , currentRow , currentColumn , nextStep ) {
11
22
const block = items [ currentRow ] . substr ( currentColumn , 1 ) ;
12
23
if ( block === '#' ) trees ++ ;
13
24
14
- currentRow ++ ;
25
+ currentRow += nextStep [ 1 ] ;
15
26
if ( ! items [ currentRow ] ) return trees ;
16
27
17
- currentColumn += 3 ;
28
+ currentColumn += nextStep [ 0 ] ;
18
29
19
30
if ( currentColumn > items [ currentRow ] . length - 1 ) {
20
31
currentColumn -= items [ currentRow ] . length ;
21
32
}
22
33
23
- return progress ( trees , currentRow , currentColumn ) ;
34
+ return progress ( trees , currentRow , currentColumn , nextStep ) ;
24
35
}
0 commit comments