Overview
Comment: | 202408 looking good so far |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ac43c4bcbc5d05f622f2810dbc044ddb |
User & Date: | nnz on 2024-12-08 15:03:16 |
Other Links: | manifest | tags |
Context
2024-12-08
| ||
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 | |
14:46 | 202408 restart with TextGrid check-in: dbcf1994d7 user: nnz tags: trunk | |
Changes
Modified aoc2024.c from [89d3d4a8c3] to [e2e9f14685].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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; 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 != '.') { char *q = strchr(p + 1, *p); while (q) { | > > > > > > > > > > > > > > > > > > > | 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 | 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 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 != '.') { char *q = strchr(p + 1, *p); while (q) { |
︙ | ︙ |
Modified aocutils.c from [a7eed73da2] to [462345b34b].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include "aocutils.h" bool TGvalid(struct TextGrid *tg, unsigned row, unsigned col) { if (row >= tg->rows) return false; if (col >= tg->cols) return false; 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; } // TODO: rewrite this shit size_t linearize2d(unsigned width, unsigned row, unsigned col) { return (row * width) + col; } | > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include "aocutils.h" bool TGvalid(struct TextGrid *tg, unsigned row, unsigned col) { if (row >= tg->rows) return false; if (col >= tg->cols) return false; 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; } |
︙ | ︙ |
Modified aocutils.h from [3f85574365] to [8f6a78c0fe].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #ifndef AOCUTILS_H_INCLUDED #define AOCUTILS_H_INCLUDED #include <stdbool.h> struct TextGrid { unsigned rows, cols; 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); 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); unsigned max3u(unsigned a, unsigned b, unsigned c); unsigned min3u(unsigned a, unsigned b, unsigned c); | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #ifndef AOCUTILS_H_INCLUDED #define AOCUTILS_H_INCLUDED #include <stdbool.h> struct TextGrid { unsigned rows, cols; 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); unsigned max3u(unsigned a, unsigned b, unsigned c); unsigned min3u(unsigned a, unsigned b, unsigned c); |
︙ | ︙ |