summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2024/10/1.c28
-rw-r--r--common.mk6
-rw-r--r--graph.h16
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;
}
diff --git a/common.mk b/common.mk
index fea030c..531ff55 100644
--- a/common.mk
+++ b/common.mk
@@ -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)
diff --git a/graph.h b/graph.h
index 0b6c5c2..6a748ae 100644
--- a/graph.h
+++ b/graph.h
@@ -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);
+}