Advent of Code

Diff
Login

Diff

Differences From Artifact [68c37aa5e0]:

To Artifact [a12f3ca546]:



1
2
3
4

















5
6
7
8
9
10
11

#include <stdio.h>
#include <stdlib.h>
#include "aocutils.h"


















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




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
27
28
29
#include <stbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "aocutils.h"

struct TextGrid {
    unsigned rows, cols;
    char *data; // may have '\n' at end of rows
};

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 (row >= tg->rows) return NULL;
    if (col >= tg->cols) return NULL;
    return 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;