Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,6 +1,6 @@ -all: aocdbg aoc aocclang aoctcc +all: aoc aocdbg aocclang aoctcc clean: rm aocdbg aoc aocclang aoctcc aocdbg: *.c *.h Index: aoc2024.c ================================================================== --- aoc2024.c +++ aoc2024.c @@ -11,11 +11,10 @@ Oh! another square of text! Idea: for all points p with an antenna find all points q>p with a corresponding frequency. For each such pair calculate the 2 antinodes and add the resulting points (if not there already) to an array. The answer to Part One is the number of elements in the array -TODO: I don't like my `linearize2d` thing! Thinking of a replacement ===================================================================== */ void aoc202408(char *data, size_t len) { (void)len; // unused argument struct TextGrid tg; @@ -30,16 +29,27 @@ char *p = data; while (*p) { while ((*p == '.') || (*p == '\n')) p++; if (*p) { // p points to an antenna + unsigned prow = TGrow(&tg, p), pcol = TGcol(&tg, p); 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)); + unsigned qrow = TGrow(&tg, q), qcol = TGcol(&tg, q); + int deltarow = (int)qrow - (int)prow; + int deltacol = (int)qcol - (int)pcol; + printf("p is at (C:%u, R:%u); q is at (C:%u, R:%u) ... delta: (C: %d, R: %d)\n", + pcol, prow, qcol, qrow, deltacol, deltarow); + int col1 = (int)pcol - deltacol, row1 = (int)prow - deltarow; + if (TGvalid(&tg, row1, col1)) { + printf("antinode at (C:%u, R:%u)\n", col1, row1); + } + int col2 = (int)qcol + deltacol, row2 = (int)qrow + deltarow; + if (TGvalid(&tg, row2, col2)) { + printf("antinode at (C:%u, R:%u)\n", col2, row2); + } q = strchr(q+1, *p); // next antenna of this type } p += 1; } }