Overview
Comment: | 202408 found the antinodes; counting to do |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ce30145a0dbabcb6b0aa81c654068fcd |
User & Date: | nnz on 2024-12-08 15:25:40 |
Other Links: | manifest | tags |
Context
2024-12-08
| ||
16:02 | 202408 1st star check-in: 6c8d6b453f user: nnz tags: trunk | |
15:25 | 202408 found the antinodes; counting to do check-in: ce30145a0d user: nnz tags: trunk | |
15:03 | 202408 looking good so far check-in: ac43c4bcbc user: nnz tags: trunk | |
Changes
Modified Makefile from [e5558dd887] to [5fd029b772].
|
| | | 1 2 3 4 5 6 7 8 | all: aoc aocdbg aocclang aoctcc clean: rm aocdbg aoc aocclang aoctcc aocdbg: *.c *.h gcc -std=c99 -pedantic -pedantic-errors \ -Werror -Wall -Wextra \ |
︙ | ︙ |
Modified aoc2024.c from [e2e9f14685] to [ffa5f1e4f3].
︙ | ︙ | |||
9 10 11 12 13 14 15 | /* === aoc202408 ======================================================= 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 | < > > > > | > > | > > > | > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | /* === aoc202408 ======================================================= 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 ===================================================================== */ void aoc202408(char *data, size_t len) { (void)len; // unused argument struct TextGrid tg; tg.data = data; 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 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 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; } } #if 0 unsigned size = 1 + strchr(data, '\n') - data; |
︙ | ︙ |