Advent of Code

Diff
Login

Diff

Differences From Artifact [a7eed73da2]:

To Artifact [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;
}