c 2024 day 14 part 1
This commit is contained in:
parent
bbe7d66027
commit
33c22748da
41
c/2024/14/restroom_redoubt.c
Normal file
41
c/2024/14/restroom_redoubt.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user