part one day 14
[advent21.git] / 13b.c
diff --git a/13b.c b/13b.c
index 092cf7a..dafd0ea 100644 (file)
--- a/13b.c
+++ b/13b.c
@@ -1,5 +1,4 @@
 #include <stdio.h>
-#include <stdbool.h>
 
 #include <uthash.h>
 
@@ -49,15 +48,14 @@ int main()
                *(to++)= '\0';
                add_dot(&grid, pnt(atoi(buf), atoi(to)));
        }
-       while (getline(&buf, &len, stdin) != -1) {
-               char *to = strchr(buf, '=');
-               fold (&grid, *(to-1), atoi(to+1));
-       }
 
        int maxx = 0, maxy = 0;
-       for (struct dot *d = grid; d!=NULL; d = d->hh.next) {
-               maxx = maxx < d->p.x ? d->p.x : maxx;
-               maxy = maxy < d->p.y ? d->p.y : maxy;
+       while (getline(&buf, &len, stdin) != -1) {
+               char *to = strchr(buf, '=')-1;
+               int foldline = atoi(to+2);
+               fold (&grid, *to, foldline--);
+               if (*to == 'x') maxx = foldline;
+               else            maxy = foldline;
        }
 
        struct dot *d;