commit 41ecca91c386d6cd183887b5221d2f6323591ac6
parent 7b2a69401e1f3d6b419a75bccdd63c9b0026b4a9
Author: bsandro <email@bsandro.tech>
Date: Sun, 18 Jan 2026 04:05:27 +0200
Friday: collecting extants
Diffstat:
| A | friday.c | | | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 70 insertions(+), 0 deletions(-)
diff --git a/friday.c b/friday.c
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include "cputime.h"
+
+#define MAP_W 42
+#define MAP_H 29
+
+typedef struct {
+ char grid[MAP_H][MAP_W];
+} Map;
+
+typedef struct {
+ int x;
+ int y;
+} Vec2;
+
+typedef struct {
+ Vec2 items[64];
+ int len;
+} ArVec2;
+
+inline bool isPlant(char c) {
+ return (c>='a'&&c<='z')||(c>='A'&&c<='Z');
+}
+
+inline int numConnections(Map *m, 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++;
+ return n;
+}
+
+int main(void) {
+ int prev = 0;
+ Map map = {0};
+ int x = 1;
+ int y = 1;
+ for (int c=getchar();c!=EOF;c=getchar()) {
+ if (c=='\n') {
+ y++;
+ x=1;
+ } else {
+ map.grid[y][x++] = c;
+ }
+ if (c=='\n'&&prev=='\n') break; // map end
+ 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};
+ }
+ }
+ }
+ }
+
+ printf("%d extants:\n", extants.len);
+ for (int i=0;i<extants.len;++i) {
+ Vec2 e = extants.items[i];
+ printf("%c at %d,%d\n", map.grid[e.y][e.x], e.x, e.y);
+ }
+
+ return 0;
+}