diff options
-rw-r--r-- | 01.c | 10 | ||||
-rw-r--r-- | 02.c | 6 | ||||
-rw-r--r-- | 03.c | 7 | ||||
-rw-r--r-- | 04.c | 7 | ||||
-rw-r--r-- | 05.c | 8 | ||||
-rw-r--r-- | input.h | 4 |
6 files changed, 26 insertions, 16 deletions
@@ -3,20 +3,22 @@ #include "input.h" #define INPUT "input/01.txt" +#define EXPECTED1 1466L +#define EXPECTED2 1491L void part1(struct input_int* input) { // compute depth variations - int result = 0; + long result = 0; for(size_t i = 1; i < input->line_count; i++) { if(input->lines[i] > input->lines[i-1]) result++; } - printf("%d\n", result); + CHECK(result, EXPECTED1) } void part2(struct input_int* input) { // compute depth variations - int result = 0; + long result = 0; int windowSum = input->lines[0] + input->lines[1] + input->lines[2]; for(size_t i = 1; i < input->line_count - 2; i++) { int newWindowSum = input->lines[i] + input->lines[i+1] + input->lines[i+2]; @@ -25,7 +27,7 @@ void part2(struct input_int* input) { windowSum = newWindowSum; } - printf("%d\n", result); + CHECK(result, EXPECTED2) } int main() { @@ -4,6 +4,8 @@ #include "input.h" #define INPUT "input/02.txt" +#define EXPECTED1 2272262L +#define EXPECTED2 2134882034L enum direction { forward, up, down }; @@ -47,7 +49,7 @@ void part1(struct input_str* input) { continue; } } - printf("%ld\n", forwardDst * downDst); + CHECK(forwardDst * downDst, EXPECTED1) } void part2(struct input_str* input) { @@ -70,7 +72,7 @@ void part2(struct input_str* input) { continue; } } - printf("%ld\n", forwardDst * downDst); + CHECK(forwardDst * downDst, EXPECTED2) } int main() { @@ -5,6 +5,9 @@ #include "input.h" #define INPUT "input/03.txt" +#define EXPECTED1 2972336L +#define EXPECTED2 0L + #define INPUT_SIZE 12 unsigned long parse_line(char* binary_line, char expected_end) { @@ -48,7 +51,7 @@ unsigned long compute_epsilon(unsigned long gamma) { void part1(struct input_str* input) { unsigned long gamma = compute_gamma(input); unsigned long epsilon = compute_epsilon(gamma); - printf("%ld\n", gamma * epsilon); + CHECK(gamma * epsilon, EXPECTED1) } unsigned long search_criteria(struct input_str* input, unsigned long criteria) { @@ -91,7 +94,7 @@ void part2(struct input_str* input) { unsigned long o2_rate = search_criteria(input, o2_criteria); unsigned long co2_criteria = compute_epsilon(o2_criteria); unsigned long co2_scrub = search_criteria(input, co2_criteria); - printf("%ld\n", o2_rate * co2_scrub); + CHECK(o2_rate * co2_scrub, EXPECTED2) } int main() { @@ -5,6 +5,9 @@ #include "input.h" #define INPUT "input/04.txt" +#define EXPECTED1 51776L +#define EXPECTED2 16830L + #define BOARD_COUNT 100 #define BOARD_SIZE 5 #define MAX_DRAW 500 @@ -104,7 +107,7 @@ void part1(struct input_str* input) { if(board_mark(&(board_list[j]), draw_list[i])) { // winning board found, print score long score = board_unmarked_sum(&(board_list[j])); - printf("%ld\n", draw_list[i] * score); + CHECK(draw_list[i] * score, EXPECTED1) return; } } @@ -134,7 +137,7 @@ void part2(struct input_str* input) { } } // print last winning - printf("%ld\n", last_score); + CHECK(last_score, EXPECTED2) } int main() { @@ -5,8 +5,8 @@ #include "input.h" #define INPUT "input/05.txt" -#define EXPECTED1 6113 -#define EXPECTED2 20373 +#define EXPECTED1 6113L +#define EXPECTED2 20373L #define RESOLUTION 1000 @@ -61,7 +61,7 @@ void part1(struct input_str* input) { } // count space points with at least a value of 2 - int result = 0; + long result = 0; for(int x = 0; x < RESOLUTION; x++) { for(int y = 0; y < RESOLUTION; y++) { if(space1[x][y] >= 2) @@ -91,7 +91,7 @@ void part2(struct input_str* input) { } // count space points with at least a value of 2 - int result = 0; + long result = 0; for(int x = 0; x < RESOLUTION; x++) { for(int y = 0; y < RESOLUTION; y++) { if(space2[x][y] >= 2) @@ -4,9 +4,9 @@ /* simple macro to check a result against an expected value */ #define CHECK(actual, expected) {\ if(actual == expected)\ - printf("%d ok\n", actual);\ + printf("%ld ok\n", actual);\ else\ - printf("%d ko, expected %d\n", actual, expected);\ + printf("%ld ko, expected %ld\n", actual, expected);\ } struct input_int { |