Advent of Code

Check-in [968127189e]
Login

Check-in [968127189e]

Overview
Comment:2025,6,1
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 968127189e437de1807e4b1f45373bb346aa36c905a8cfd9c6493f99ec3e2c01
User & Date: nnz on 2025-12-06 12:09:22.492
Other Links: manifest | tags
Context
2025-12-08
11:12
2025, day 7, part 1 check-in: 7b791fa5ed user: nnz tags: trunk
2025-12-06
12:09
2025,6,1 check-in: 968127189e user: nnz tags: trunk
2025-12-05
20:55
incomplete attempt at day 5, part 2 check-in: 48d82159c3 user: nnz tags: trunk
Changes
Modified aoc2025.c from [07f8f60a3d] to [2a923d68eb].
11
12
13
14
15
16
17
18























































19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* === aocYYYYDD =======================================================
===================================================================== */
void aocYYYYDD(char *data, size_t len) {
    (void)len; // unused argument
}

#endif
























































/* === aoc202505 =======================================================
===================================================================== */
struct Range {
    long long unsigned lo, hi;
};

int ascending(const void *a, const void *b) {
    const struct Range *aa = a, *bb = b;
    if (aa->lo < bb->lo) return -1;
    if (aa->lo > bb->lo) return 1;
    return 0;
}

void aoc202505(char *data, size_t len) {








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






|







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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* === aocYYYYDD =======================================================
===================================================================== */
void aocYYYYDD(char *data, size_t len) {
    (void)len; // unused argument
}

#endif

/* === aoc202506 =======================================================
===================================================================== */
static long long unsigned add2506(long long unsigned v[4][1024], int lin, int col) {
    long long unsigned sum = 0;
    for (int k = 0; k < lin; k++) sum += v[k][col];
    return sum;
}
static long long unsigned mul2506(long long unsigned v[4][1024], int lin, int col) {
    long long unsigned sum = 1;
    for (int k = 0; k < lin; k++) sum *= v[k][col];
    return sum;
}

static long long unsigned input_202506[4][1024];
void aoc202506(char *data, size_t len) {
    (void)len; // unused argument
    char *X;
    for (;;) {
        X = strchr(data, '\n');
        if (!X) break;
        *X = 'X';
    }
    int lin = 0, col;
    char *err = data;
    for (;;) { // for each line
        col = 0;
        for (;;) { // for each number
            while (isspace(*err)) err++;
            long long unsigned tmp = strtoull(err, &err, 10);
            if ((*err == 'X') && (tmp == 0)) { err++; break; }
            input_202506[lin][col++] = tmp;
        }
        lin++;
        printf("got line %d with %d columns\n", lin, col);
        if ((*err == '+') || (*err == '*')) break;
    }
    printf("from %llu to %llu\n", input_202506[0][0], input_202506[lin-1][col-1]);
    col = 0;
    while (isspace(*err)) err++;
    long long unsigned sum = 0;
    for (;;) {
        switch (*err) {
            default: /* does not happen! */ break;
            case 'X': break;
            case '+': sum += add2506(input_202506, lin, col); break;
            case '*': sum += mul2506(input_202506, lin, col); break;
        }
        if (*err == 'X') break;
        col++;
        err++;
        while (isspace(*err)) err++;
    }
    printf("part 1: %llu\n", sum);
}

/* === aoc202505 =======================================================
===================================================================== */
struct Range {
    long long unsigned lo, hi;
};

static int ascending(const void *a, const void *b) {
    const struct Range *aa = a, *bb = b;
    if (aa->lo < bb->lo) return -1;
    if (aa->lo > bb->lo) return 1;
    return 0;
}

void aoc202505(char *data, size_t len) {
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
#include <stddef.h>
#include "aocdailies.h"

aocfunc *aocselect(unsigned y, unsigned d) {
    aocfunc *p;
    switch (y * 100 + d) {
        default: p = NULL; break;


        case 202505: p = aoc202505; break;
        case 202504: p = aoc202504; break;
        case 202503: p = aoc202503; break;
        case 202502: p = aoc202502; break;
        case 202501: p = aoc202501; break;

        //   YYYYdd ==>  aocYYYYdd








>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stddef.h>
#include "aocdailies.h"

aocfunc *aocselect(unsigned y, unsigned d) {
    aocfunc *p;
    switch (y * 100 + d) {
        default: p = NULL; break;

        case 202506: p = aoc202506; break;
        case 202505: p = aoc202505; break;
        case 202504: p = aoc202504; break;
        case 202503: p = aoc202503; break;
        case 202502: p = aoc202502; break;
        case 202501: p = aoc202501; break;

        //   YYYYdd ==>  aocYYYYdd
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
#ifndef AOCDAILIES_H_INCLUDED
#define AOCDAILIES_H_INCLUDED

#include <stddef.h>

typedef void aocfunc(char *, size_t);
aocfunc *aocselect(unsigned, unsigned);


aocfunc aoc202505;
aocfunc aoc202504;
aocfunc aoc202503;
aocfunc aoc202502;
aocfunc aoc202501;

aocfunc aoc202422;








>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef AOCDAILIES_H_INCLUDED
#define AOCDAILIES_H_INCLUDED

#include <stddef.h>

typedef void aocfunc(char *, size_t);
aocfunc *aocselect(unsigned, unsigned);

aocfunc aoc202506;
aocfunc aoc202505;
aocfunc aoc202504;
aocfunc aoc202503;
aocfunc aoc202502;
aocfunc aoc202501;

aocfunc aoc202422;