easters

easters.dev solutions (C)
git clone git://bsandro.tech/easters
Log | Files | Refs | LICENSE

commit 0d11e4f4432083b42d085fa93354c776b8a5b1be
parent 41ecca91c386d6cd183887b5221d2f6323591ac6
Author: bsandro <email@bsandro.tech>
Date:   Sat, 24 Jan 2026 10:50:24 +0200

friday todo

Diffstat:
Mfriday.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 52 insertions(+), 20 deletions(-)

diff --git a/friday.c b/friday.c @@ -12,26 +12,58 @@ typedef struct { typedef struct { int x; int y; -} Vec2; + char name; + bool processed; +} Extant; typedef struct { - Vec2 items[64]; + Extant items[64]; int len; -} ArVec2; +} ArExtants; + +struct Node; +typedef struct { + int len; + struct Node *n; +} Connection; + +typedef struct { + char name; + Connection *conns; +} Node; + +typedef struct { + Node items[256]; + int len; +} ArNodes; inline bool isPlant(char c) { return (c>='a'&&c<='z')||(c>='A'&&c<='Z'); } -inline int numConnections(Map *m, int x, int y) { +inline int numConnections(Map *map, int x, int y) { int n = 0; - if (m->grid[y-1][x]=='|') n++; - if (m->grid[y+1][x]=='|') n++; - if (m->grid[y][x-1]=='-') n++; - if (m->grid[y][x+1]=='-') n++; + if (map->grid[y-1][x]=='|') n++; + if (map->grid[y+1][x]=='|') n++; + if (map->grid[y][x-1]=='-') n++; + if (map->grid[y][x+1]=='-') n++; return n; } +ArExtants findExtants(Map *map) { + ArExtants extants = {0}; + for (int y=1;y<MAP_H-1;++y) { + for (int x=1;x<MAP_W-1;++x) { + if (isPlant(map->grid[y][x])) { + if (numConnections(map, x, y)==1) { + extants.items[extants.len++] = (Extant){x,y,map->grid[y][x],false}; + } + } + } + } + return extants; +} + int main(void) { int prev = 0; Map map = {0}; @@ -48,23 +80,23 @@ int main(void) { prev = c; } - ArVec2 extants = {0}; - - for (int y=1;y<MAP_H-1;++y) { - for (int x=1;x<MAP_W-1;++x) { - if (isPlant(map.grid[y][x])) { - if (numConnections(&map, x, y)==1) { - extants.items[extants.len++] = (Vec2){x,y}; - } - } - } - } + ArExtants extants = findExtants(&map); printf("%d extants:\n", extants.len); for (int i=0;i<extants.len;++i) { - Vec2 e = extants.items[i]; + Extant e = extants.items[i]; printf("%c at %d,%d\n", map.grid[e.y][e.x], e.x, e.y); } + ArNodes nodes = {0}; + for (int i=0;i<extants.len;++i) { + if (!extants.items[i].processed) { + nodes.items[nodes.len++] = (Node){extants.items[i].name, NULL}; + // traverse map, fill nodes with distances + // feedback loop - have to mark extants as processed when we finish traversal + // the direction of movement is important for parsing numbers + } + } + return 0; }