init day 2
This commit is contained in:
parent
9f97e0a390
commit
464436611f
4 changed files with 9 additions and 9 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -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",
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
#include "include/days.h"
|
||||
#include "include/day1_input.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -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)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#include "day1_input.h"
|
||||
|
||||
char *day_1_part_1(void);
|
Loading…
Add table
Reference in a new issue