Advent of Code

Check-in [dbcf1994d7]
Login

Check-in [dbcf1994d7]

Overview
Comment:202408 restart with TextGrid
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dbcf1994d78960a5b521ad0e1f734833182da2da7dcc747c9de5c11521bdfb07
User & Date: nnz on 2024-12-08 14:46:00
Other Links: manifest | tags
Context
2024-12-08
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
14:40
merge TextGrid check-in: 2f2a7645d9 user: nnz tags: trunk
Changes

Modified aoc2024.c from [50f843a30c] to [89d3d4a8c3].

14
15
16
17
18
19
20





21
22
23
24
25
26
27
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32







+
+
+
+
+







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;
    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 != '.') {
45
46
47
48
49
50
51

52
53
54
55
56
57
58
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+







                    }
                    q = strchr(q + 1, *p);
                }
            }
        }
    }
    printf("There are %u antinodes within the map.\n", nanti);
    #endif
}

/* === aoc202407 =======================================================
   Part one looks easy
   Part two also easy
 ===================================================================== */

Modified aocutils.h from [838e050968] to [3f85574365].

1
2


3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10
11


+
+







#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);