Advent of Code

Diff
Login

Diff

Differences From Artifact [7ac7fd4de9]:

To Artifact [4c494bd7a9]:


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
30
31
32
33

34
35
36


37
38
39
40
41
42
43
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h"
#include "aocutils.h"

void aoc202405(char *data, size_t len) {
    (void)len; // unused argument
    // assume (by visual inspection) all page numbers `pn` are between 10 and 99
    unsigned pagepair[1200][2], npp = 0;
    char *line = strtok(data, "\n");
    while (strchr(line, '|')) {
        char *err;
        pagepair[npp][0] = strtoul(line, &err, 10);
        err += 1; // skip '|'
        pagepair[npp][1] = strtoul(line, &err, 10);
        npp++;
        line = strtok(NULL, "\n");
    }
    printf("%u\n", pagepair[0][0]);
    unsigned update[512], nupdates, maxupdates = 0;
    while ((line = strtok(NULL, "\n")) != NULL) {
        nupdates = 0;
        char *err = line;
        for (;;) {
            update[nupdates++] = strtoul(err, &err, 10);
            if (*err == ',') err++;
            else break;
        }
        if (nupdates > maxupdates) maxupdates = nupdates;

    }
    printf("%u nax updates\n", maxupdates);
}


static size_t rcmap(unsigned size, unsigned row, unsigned col) {
    return row * (size + 1) + col;
}

static bool masat(char *data, unsigned size, unsigned row, unsigned col, int drow, int dcol) {
    int maxrow = (int)row + 3*drow;
    int maxcol = (int)col + 3*dcol;











<
|









<
|








|
>
|
<
|
>
>







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
30
31
32
33

34
35
36
37
38
39
40
41
42
43
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h"
#include "aocutils.h"

void aoc202405(char *data, size_t len) {
    (void)len; // unused argument

    unsigned pagepair[1200][2], npp = 0; // 1200 works for me
    char *line = strtok(data, "\n");
    while (strchr(line, '|')) {
        char *err;
        pagepair[npp][0] = strtoul(line, &err, 10);
        err += 1; // skip '|'
        pagepair[npp][1] = strtoul(line, &err, 10);
        npp++;
        line = strtok(NULL, "\n");
    }

    unsigned update[32], nupdates, maxupdates = 0; // 32 works dor me
    while ((line = strtok(NULL, "\n")) != NULL) {
        nupdates = 0;
        char *err = line;
        for (;;) {
            update[nupdates++] = strtoul(err, &err, 10);
            if (*err == ',') err++;
            else break;
        }
        for (size_t k = 0; k < nupdates; k++) {
            //...
        }

    }
}

static size_t rcmap(unsigned size, unsigned row, unsigned col) {
    return row * (size + 1) + col;
}

static bool masat(char *data, unsigned size, unsigned row, unsigned col, int drow, int dcol) {
    int maxrow = (int)row + 3*drow;
    int maxcol = (int)col + 3*dcol;