commit 0e66260d2c5bae93979118ec70d5eca78853c91a
parent 5820e9bd6310906b5f21b897da3182a893762a7c
Author: bsandro <email@bsandro.tech>
Date: Fri, 12 Dec 2025 10:24:37 +0200
day12 parsing
Diffstat:
| M | day11.c | | | 3 | +-- |
| A | day12.c | | | 89 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 90 insertions(+), 2 deletions(-)
diff --git a/day11.c b/day11.c
@@ -1,8 +1,7 @@
/*
Test input #1 works only with part1 of the puzzle.
Test input #2 works only with part2 of the puzzle.
-Thing crashes pretty hard if 'svr'/'our' nodes weren't found, I don't care much.
- */
+*/
#include <stdio.h>
#include <string.h>
diff --git a/day12.c b/day12.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include "cputime.h"
+
+
+#define BUF_LEN 3
+
+int btoi(int bufl, int buf[bufl]) {
+ int num = 0;
+ for (int i=0;i<bufl;++i) num = num*10+buf[i];
+ return num;
+}
+
+typedef struct {
+ char shape[3][3];
+} Present;
+
+typedef struct {
+ int w;
+ int h;
+ int req[6];
+ int req_l;
+} Region;
+
+void print_present(Present p) {
+ for (int y=0;y<3;++y) {
+ for (int x=0;x<3;++x) {
+ putchar(p.shape[y][x]);
+ }
+ putchar('\n');
+ }
+}
+
+int main(void) {
+ Present presents[6] = {0};
+ int cur_present = 0;
+ bool parse_presents = true;
+ int shape_x = 0;
+ int shape_y = 0;
+ int buf[BUF_LEN];
+ int bufl = 0;
+ Region regions[1000] = {0};
+ int regions_l = 0;
+ for (int c=getchar();c!=EOF;c=getchar()) {
+ if (parse_presents) {
+ if (c>='0'&&c<='9') {
+ cur_present = c-'0';
+ shape_x = 0;
+ shape_y = 0;
+ } else if (c=='.'||c=='#') {
+ presents[cur_present].shape[shape_y][shape_x++] = c;
+ } else if (c=='\n'&&shape_x>0) {
+ shape_y++;
+ shape_x = 0;
+ if (cur_present==5&&shape_y>2) parse_presents = false;
+ }
+ } else {
+ if (c>='0'&&c<='9') buf[bufl++] = c-'0';
+ else if (c=='x') {
+ regions[regions_l].w = btoi(bufl, buf);
+ bufl = 0;
+ } else if (c==':') {
+ regions[regions_l].h = btoi(bufl, buf);
+ bufl = 0;
+ } else if ((c==' '||c=='\n')&&bufl>0) {
+ Region *reg = ®ions[regions_l];
+ reg->req[reg->req_l++] = btoi(bufl, buf);
+ bufl = 0;
+ if (c=='\n') regions_l++;
+ }
+ }
+ }
+
+ /*for (int p=0;p<6;++p) {
+ printf("present %d:\n", p);
+ print_present(presents[p]);
+ putchar('\n');
+ }
+ printf("regions: %d\n", regions_l);
+ for (int r=0;r<regions_l;++r) {
+ Region *reg = ®ions[r];
+ printf("----------\nregion %dx%d\n", reg->w, reg->h);
+ for (int i=0;i<reg->req_l;++i) {
+ printf("%2d", reg->req[i]);
+ }
+ printf("\n");
+ }*/
+ return 0;
+}