Advent of Code

Check-in [2f2a7645d9]
Login

Check-in [2f2a7645d9]

Overview
Comment:merge TextGrid
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2f2a7645d9e6454bdeef462109f208e7eb67d69e4a8aeb647f4a8a5bc6bae5fb
User & Date: nnz on 2024-12-08 14:40:43
Other Links: manifest | tags
Context
2024-12-08
14:46
202408 restart with TextGrid check-in: dbcf1994d7 user: nnz tags: trunk
14:40
merge TextGrid check-in: 2f2a7645d9 user: nnz tags: trunk
13:54
added test file Leaf check-in: d487b46741 user: nnz tags: TextGrid
13:23
redo some formatting check-in: 6d26cab7c2 user: nnz tags: trunk
Changes

Modified aocutils.c from [68c37aa5e0] to [a7eed73da2].


1
2
3
4











5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+




+
+
+
+
+
+
+
+
+
+
+







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

size_t text2array(unsigned **dst, const char *r) {
    unsigned *a = malloc(512 * sizeof *a);
    size_t na = 0, sa = 512;

Modified aocutils.h from [475433f577] to [838e050968].

1
2
3








4

5
6
7
8
9
10
11
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

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

#endif