22
33#include  <stdio.h> 
44#include  <stdlib.h> 
5+ #include  <stdint.h> 
56#include  "../../../shared/JohnnyJayJay/aoc.h" 
67
7- int  traverse (u_int32_t *  levels , int  lines , int  width , int  x_step , int  y_step ) {
8+ int  traverse (uint32_t *  levels , int  lines , int  width , int  x_step , int  y_step ) {
89 int  x_pos  =  0 ;
910 int  tree_count  =  0 ;
1011 for  (int  i  =  0 ; i  <  lines ; i  +=  y_step ) {
11-  u_int32_t  level  =  levels [i ];
12-  if  ((level  >> (width  -  1  -  x_pos )) &  (( u_int32_t )  1 ) ) {
12+  uint32_t  level  =  levels [i ];
13+  if  ((level  >> (width  -  1  -  x_pos )) &  1 ) {
1314 tree_count ++ ;
1415 }
1516 x_pos  =  (x_pos  +  x_step ) % width ;
@@ -21,9 +22,9 @@ int main(int argc, char** argv) {
2122 FILE *  file  =  fopen (argv [1 ], "r" );
2223 int  lines  =  count_lines (file );
2324 int  width  =  chars_until (file , '\n' , 1 );
24-  u_int32_t *  levels  =  malloc (sizeof (u_int32_t ) *  lines );
25+  uint32_t *  levels  =  malloc (sizeof (uint32_t ) *  lines );
2526 for  (int  i  =  0 ; i  <  lines ; i ++ ) {
26-  u_int32_t  level  =  0 ;
27+  uint32_t  level  =  0 ;
2728 int  spot ;
2829 while  ((spot  =  fgetc (file )) !=  '\n'  &&  spot  !=  EOF ) {
2930 level  <<= 1 ;
@@ -32,12 +33,12 @@ int main(int argc, char** argv) {
3233 levels [i ] =  level ;
3334 }
3435
35-  u_int64_t  first  =  traverse (levels , lines , width , 3 , 1 );
36+  uint64_t  first  =  traverse (levels , lines , width , 3 , 1 );
3637 printf ("You encounter %lu trees the first slope.\n" , first );
37-  u_int64_t  second  =  traverse (levels , lines , width , 1 , 1 );
38-  u_int64_t  third  =  traverse (levels , lines , width , 5 , 1 );
39-  u_int64_t  fourth  =  traverse (levels , lines , width , 7 , 1 );
40-  u_int64_t  fiveth  =  traverse (levels , lines , width , 1 , 2 );
38+  uint64_t  second  =  traverse (levels , lines , width , 1 , 1 );
39+  uint64_t  third  =  traverse (levels , lines , width , 5 , 1 );
40+  uint64_t  fourth  =  traverse (levels , lines , width , 7 , 1 );
41+  uint64_t  fiveth  =  traverse (levels , lines , width , 1 , 2 );
4142 printf ("The trees on all slopes multiplied together: %lu\n" , first  *  second  *  third  *  fourth  *  fiveth );
4243
43- }
44+ }
0 commit comments