Index: aoc2024.c ================================================================== --- aoc2024.c +++ aoc2024.c @@ -23,10 +23,29 @@ tg.cols = strchr(data, '\n') - data + 1; tg.rows = tg.cols - 1; // rows includes the '\n' #if 0 unsigned anti[256][2]; // locations of antinodes unsigned nanti = 0; + #endif + + char *p = data; + while (*p) { + while ((*p == '.') || (*p == '\n')) p++; + if (*p) { + // p points to an antenna + char *q = strchr(p+1, *p); + while (q) { + // q points to an antenna of the same type as p + printf("p is at (C:%u, R:%u); q is at (C:%u, R:%u)\n", + TGcol(&tg, p), TGrow(&tg, p), + TGcol(&tg, q), TGrow(&tg, q)); + q = strchr(q+1, *p); // next antenna of this type + } + p += 1; + } + } + #if 0 unsigned size = 1 + strchr(data, '\n') - data; for (unsigned row = 0; row < size-1; row++) { for (unsigned col = 0; col < size-1; col++) { char *p = data + linearize2d(size, row, col); if (*p != '.') { Index: aocutils.c ================================================================== --- aocutils.c +++ aocutils.c @@ -9,10 +9,16 @@ return true; } char *TGcharptr(struct TextGrid *tg, unsigned row, unsigned col) { if (!TGvalid(tg, row, col)) return NULL; return tg->data + (row * tg->cols) + col; +} +unsigned TGcol(struct TextGrid *tg, char *p) { + return (p - tg->data) % tg->cols; +} +unsigned TGrow(struct TextGrid *tg, char *p) { + return (p - tg->data) / tg->cols; } // TODO: rewrite this shit size_t linearize2d(unsigned width, unsigned row, unsigned col) { return (row * width) + col; Index: aocutils.h ================================================================== --- aocutils.h +++ aocutils.h @@ -8,10 +8,12 @@ char *data; // may have '\n' at end of rows }; bool TGvalid(struct TextGrid *tg, unsigned row, unsigned col); char *TGcharptr(struct TextGrid *tg, unsigned row, unsigned col); +unsigned TGcol(struct TextGrid *tg, char *p); +unsigned TGrow(struct TextGrid *tg, char *p); size_t linearize2d(unsigned width, unsigned row, unsigned col); // TODO size_t text2array(unsigned **dst, const char *txt); size_t slurp(char **dst, const char *filename); unsigned distance(unsigned a, unsigned b);