summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2021-12-05 22:53:32 +0100
committerVincent Douillet <vincent@vdouillet.fr>2021-12-05 22:53:32 +0100
commit8a8417207729cb92ae4f3038a3a8bd5e6a0c0ce7 (patch)
treea1366131e356ffadfa081c1561c968a2570a9843
parent4c42453d856053bb49affef7c165397e5c16d9eb (diff)
add expected results to previous days
-rw-r--r--01.c10
-rw-r--r--02.c6
-rw-r--r--03.c7
-rw-r--r--04.c7
-rw-r--r--05.c8
-rw-r--r--input.h4
6 files changed, 26 insertions, 16 deletions
diff --git a/01.c b/01.c
index 33c52aa..e2e97ba 100644
--- a/01.c
+++ b/01.c
@@ -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() {
diff --git a/02.c b/02.c
index 30af77f..9814501 100644
--- a/02.c
+++ b/02.c
@@ -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() {
diff --git a/03.c b/03.c
index 738062c..36cc0d4 100644
--- a/03.c
+++ b/03.c
@@ -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() {
diff --git a/04.c b/04.c
index 7077b65..499461b 100644
--- a/04.c
+++ b/04.c
@@ -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() {
diff --git a/05.c b/05.c
index eeac8ce..3e9aa10 100644
--- a/05.c
+++ b/05.c
@@ -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)
diff --git a/input.h b/input.h
index d386da0..f7593ce 100644
--- a/input.h
+++ b/input.h
@@ -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 {