42 lines
982 B
C
42 lines
982 B
C
#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;
|
|
}
|