diff --git a/2021/day-09/Justfile b/2021/day-09/Justfile index 511a4fd..91d0db5 100644 --- a/2021/day-09/Justfile +++ b/2021/day-09/Justfile @@ -1,5 +1,5 @@ @part PART INPUT_FILE="inputs/puzzle.txt": - gcc -std=c17 -Werror -Wextra -o part_{{PART}} common.c part_{{PART}}.c + gcc -std=c17 -Werror -Wextra -pedantic -o part_{{PART}} common.c part_{{PART}}.c ./part_{{PART}} {{INPUT_FILE}} clean: diff --git a/2021/day-09/common.c b/2021/day-09/common.c index b26eada..23f815c 100644 --- a/2021/day-09/common.c +++ b/2021/day-09/common.c @@ -6,7 +6,7 @@ int MAP_WIDTH = 0; int MAP_HEIGHT = 0; -int MAP[100][100]; +int MAP[MAP_MAX_Y][MAP_MAX_X]; void read_file(char* path) { FILE* fp = fopen(path, "r"); @@ -37,6 +37,8 @@ void read_file(char* path) { } MAP_HEIGHT = y; + + fclose(fp); } void print_map(int map[100][100]) { diff --git a/2021/day-09/common.h b/2021/day-09/common.h index f12a72a..d2eb9c6 100644 --- a/2021/day-09/common.h +++ b/2021/day-09/common.h @@ -1,8 +1,10 @@ #pragma once +#define MAP_MAX_Y 100 +#define MAP_MAX_X 100 extern int MAP_WIDTH; extern int MAP_HEIGHT; -extern int MAP[100][100]; +extern int MAP[MAP_MAX_Y][MAP_MAX_X]; typedef int (*result_fn)(int, int, int); diff --git a/2021/day-09/part_two.c b/2021/day-09/part_two.c index f1cbdb7..032f21d 100644 --- a/2021/day-09/part_two.c +++ b/2021/day-09/part_two.c @@ -7,7 +7,7 @@ int BASIN_IDX = 0; int BASINS[BASIN_COUNT] = { 0 }; -int scout_basin(int x, int y, int marked[100][100]) { +int scout_basin(int x, int y, int marked[MAP_MAX_Y][MAP_MAX_X]) { marked[y][x] = 1; int count = 1; @@ -31,7 +31,7 @@ int scout_basin(int x, int y, int marked[100][100]) { } int calculate_basin_size(int x, int y, int cur) { - int marked[100][100] = { 0 }; + int marked[MAP_MAX_Y][MAP_MAX_X] = { 0 }; int basin_size = scout_basin(x, y, marked); BASINS[BASIN_IDX] = basin_size; BASIN_IDX++;