diff options
-rw-r--r-- | 2024/10/1.c | 28 | ||||
-rw-r--r-- | common.mk | 6 | ||||
-rw-r--r-- | graph.h | 16 |
3 files changed, 27 insertions, 23 deletions
diff --git a/2024/10/1.c b/2024/10/1.c index e1aee04..315dd55 100644 --- a/2024/10/1.c +++ b/2024/10/1.c @@ -6,10 +6,7 @@ bool debug = true; - - - - +/* This is the stuff of ideas. typedef struct Stack { void* value; struct Stack* below; @@ -28,12 +25,14 @@ push(Stack* s, void* value) { t->below = s; t->value = value; return t; -} +} */ +// This global will die. int score = 0; void travel(Graph2D* g, Coordinates c) { + // Utility TBD // g->visited[c.y][c.x] = true; if (debug) { @@ -52,7 +51,7 @@ travel(Graph2D* g, Coordinates c) return; } for (int i = 0; i < DIRECTIONS; i++) { - if (valid(g, cardinal[i])) { + if (graph_valid(g, cardinal[i])) { if (debug) { printf("%d,%d\n", cardinal[i].x, cardinal[i].y); printf("%d\n", g->e[cardinal[i].y][cardinal[i].x]); @@ -80,8 +79,10 @@ main() exit(1); } - Graph2D* g = ingest(in); + Graph2D* g = graph_ingest(in); + /* Hash map from Coordinates of each starting point to their scores. + Pass to each travel, along with launch coordinates. */ hashmap* map = hashmap_create(); for (int i = 0; i < g->height; i++) { for (int j = 0; j < g->width; j++) { @@ -92,17 +93,6 @@ main() } } } - - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { - printf("%c", g->e[i][j]); - } - putchar('\n'); - free(g->e[i]); - free(g->visited[i]); - } - free(g->e); - free(g->visited); - free(g); + return 0; } @@ -1,2 +1,4 @@ -CFLAGS = -g -Wall -LDFLAGS = -I ../../c-hashmap -L ../../c-hashmap -lhashmap +CFLAGS = -g -Wall -O2 -march=native -I ../../ -I ../../c-hashmap/ +LDFLAGS = -L ../../c-hashmap/ -lhashmap +.c: + $(CC) -o $@ $< $(LDFLAGS) $(CFLAGS) @@ -15,7 +15,7 @@ typedef struct { } Coordinates; bool -valid(Graph2D* g, Coordinates c) +graph_valid(Graph2D* g, Coordinates c) { return c.x >= 0 && c.x < g->width && c.y >= 0 && c.y < g->height; } @@ -23,7 +23,7 @@ valid(Graph2D* g, Coordinates c) /* Reads from the input until exhausted. Returns memory which must be freed by the caller. */ Graph2D* -ingest(FILE* in) +graph_ingest(FILE* in) { char *t = getall(in); char *s = t; @@ -71,3 +71,15 @@ ingest(FILE* in) free(t); return g; } + +void +graph_free(Graph2D* g) +{ + for (int i = 0; i < g->height; i++) { + free(g->e[i]); + free(g->visited[i]); + } + free(g->e); + free(g->visited); + free(g); +} |