diff --git a/.vscode/launch.json b/.vscode/launch.json index f960f47..a4a2d2a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "request": "launch", "name": "Launch", "program": "${workspaceFolder}/build/adventofcode/adventofcode", - "args": ["2024", "1", "2"], + "args": ["2024", "2", "1"], "cwd": "${workspaceFolder}", "preLaunchTask": "CMake: build", } diff --git a/2024/CMakeLists.txt b/2024/CMakeLists.txt index e28b2f6..b48df57 100644 --- a/2024/CMakeLists.txt +++ b/2024/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(2024 SHARED) -foreach(i RANGE 1 1) +foreach(i RANGE 1 2) set(out_path "${CMAKE_CURRENT_SOURCE_DIR}/src/include/day${i}_input.h") add_custom_command( OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/include/day${i}_input.h" @@ -17,4 +17,5 @@ target_link_libraries(2024 m) target_sources(2024 PRIVATE src/day1.c + src/day2.c ) \ No newline at end of file diff --git a/2024/src/day1.c b/2024/src/day1.c index 02e209b..11767ad 100644 --- a/2024/src/day1.c +++ b/2024/src/day1.c @@ -1,4 +1,4 @@ -#include "include/days.h" +#include "include/day1_input.h" #include #include #include @@ -12,7 +12,7 @@ struct list_pair { struct list_ctx *right; }; -struct list_pair *parse_input() { +struct list_pair *parse_input_day1() { struct list_pair *ctx = malloc(sizeof(struct list_pair)); ctx->left = malloc(sizeof(struct list_ctx)); ctx->left->list = malloc(1000 * sizeof(u_int32_t)); @@ -31,6 +31,7 @@ struct list_pair *parse_input() { if (list_buf_len) { ctx->left->list[list_i] = strtoul(list_buf, NULL, 10); list_buf_len = 0; + free(list_buf); list_buf = NULL; }; break; @@ -38,6 +39,7 @@ struct list_pair *parse_input() { ctx->right->list[list_i] = strtoul(list_buf, NULL, 10); list_i++; list_buf_len = 0; + free(list_buf); list_buf = NULL; break; } @@ -68,7 +70,7 @@ void selection_sort(struct list_ctx *ctx) { } char *day_1_part_1() { - struct list_pair *pair = parse_input(); + struct list_pair *pair = parse_input_day1(); selection_sort(pair->left); selection_sort(pair->right); @@ -91,7 +93,7 @@ char *day_1_part_1() { } char *day_1_part_2() { - struct list_pair *pair = parse_input(); + struct list_pair *pair = parse_input_day1(); int total = 0; // TODO: do not the O(n^2) diff --git a/2024/src/include/days.h b/2024/src/include/days.h deleted file mode 100644 index 789e944..0000000 --- a/2024/src/include/days.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "day1_input.h" - -char *day_1_part_1(void); \ No newline at end of file