From ece6ff1139b8e5a6d4d579625d31edc69f02e499 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Fri, 6 Dec 2024 05:51:15 +0000 Subject: [PATCH] day 6 reduce state size --- day06/sol.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/day06/sol.c b/day06/sol.c index f5fc423..8093fa0 100644 --- a/day06/sol.c +++ b/day06/sol.c @@ -144,20 +144,20 @@ int solve(struct grid *g) { } // returns whether the chosen grid will cause the guard to get stuck in a loop -bool loops(struct grid *g, struct point start, uint16_t* state) { +bool loops(struct grid *g, struct point start, uint8_t* state) { int x = start.x; int y = start.y; int dx = 0, dy = -1; // up int stride = g->x; //printf("loops(%d,%d)\n", x,y); while(inbounds(g, x, y)) { - uint16_t dir = 15; + uint8_t dir = 15; if (dx == 1) { dir = 1; } else if (dx == -1) { dir = 2; } else if (dy == 1) { dir = 4; } else if (dy == -1) { dir = 8; } - uint16_t *s = &state[y*stride + x]; + uint8_t *s = &state[y*stride + x]; if ((*s & dir) != 0) { // revisited a state, loop! return true; @@ -183,8 +183,8 @@ int solve2(struct grid *g) { int count = 0; int ox, oy; // obstacle coords struct point p = startingPoint(g); - size_t state_size = g->x * g->y * sizeof(uint16_t); - uint16_t *state = xrealloc(NULL, state_size); + size_t state_size = g->x * g->y * sizeof(uint8_t); + uint8_t *state = xrealloc(NULL, state_size); for (oy = 0; oy < g->y; oy++) for (ox = 0; ox < g->x; ox++) { int c = g->A[oy][ox];