diff --git a/c/2024/14/restroom_redoubt.c b/c/2024/14/restroom_redoubt.c new file mode 100644 index 0000000..a810886 --- /dev/null +++ b/c/2024/14/restroom_redoubt.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include "../../lib/aoc.h" + +#define WIDTH 101 +#define HEIGHT 103 +#define CYCLES 100 + +int main() { + char *line; + + int px, py, vx, vy; + + int q1 = 0, q2 = 0, q3 = 0, q4 = 0; + + while((line = aoc_read_line()) != NULL) { + sscanf(line, "p=%d,%d v=%d,%d", &px, &py, &vx, &vy); + // printf("%s\n[%d, %d] [%d, %d]\n\n", line, px, py, vx, vy); + for (int i = 0; i < CYCLES; i++) { + px += vx; + px = (px + WIDTH) % WIDTH; + py += vy; + py = (py + HEIGHT) % HEIGHT; + } + printf("[%d, %d] [%d, %d]\n\n", px, py, vx, vy); + if (px < WIDTH / 2 && py < HEIGHT / 2) q1++; + if (px > WIDTH / 2 && py < HEIGHT / 2) q2++; + if (px < WIDTH / 2 && py > HEIGHT / 2) q3++; + if (px > WIDTH / 2 && py > HEIGHT / 2) q4++; + } + + printf("%d %d %d %d\n", q1, q2, q3, q4); + printf("Part 1: %lld\n", q1 * q2 * q3 * q4); + //printf("Part 2: %lld\n", cost_2); + + aoc_free(); + return 0; +}