Advent of Code

Check-in [c6ad316f4d]
Login

Check-in [c6ad316f4d]

Overview
Comment:fixed possible bug
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c6ad316f4d6ba70f925200485d880c72f0c046608f0a3a55d6833e6d958e428b
User & Date: nnz on 2024-12-07 14:37:48
Other Links: manifest | tags
Context
2024-12-07
14:39
fixed possible bug (2) check-in: afa0bfe340 user: nnz tags: trunk
14:37
fixed possible bug check-in: c6ad316f4d user: nnz tags: trunk
13:52
removed dead code check-in: 278fc62fcc user: nnz tags: trunk
Changes

Modified aoc2024.c from [5ec424337a] to [1242bf1894].

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
static int operatorsrequired(unsigned long long v, unsigned long long *a, size_t n, int minop) {
    // assumes no unsigned long long overflowing
    if (n == 1) {
        if (v == *a) return minop;
        return 0;
    }
    unsigned long long tmp = a[1];

    a[1] = a[0] + tmp;
    int p = operatorsrequired(v, a+1, n-1, (minop > 2)?3:2);
    a[1] = tmp;
    if (p) return p;
    a[1] = a[0] * tmp;
    p = operatorsrequired(v, a+1, n-1, (minop > 2)?3:2);
    a[1] = tmp;
    if (p) return p;
    a[1] = concat(a[0], tmp);
    p = operatorsrequired(v, a+1, n-1, 3);
    a[1] = tmp;




    return p;
}

void aoc202407(char *data, size_t len) {
    (void)len; // unused argument
    unsigned long long calibrationtotal = 0, calibration3total = 0;
    char *line = strtok(data, "\n");
    unsigned long long number[50], nnumber;







>

|

<

|

|
|
|
|
>
>
>
>
|







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
static int operatorsrequired(unsigned long long v, unsigned long long *a, size_t n, int minop) {
    // assumes no unsigned long long overflowing
    if (n == 1) {
        if (v == *a) return minop;
        return 0;
    }
    unsigned long long tmp = a[1];
    int pplus, pmult, pconcat = 0;
    a[1] = a[0] + tmp;
    pplus = operatorsrequired(v, a+1, n-1, 2);
    a[1] = tmp;

    a[1] = a[0] * tmp;
    pmult = operatorsrequired(v, a+1, n-1, 2);
    a[1] = tmp;
    if (!pplus && !pmult) {
        a[1] = concat(a[0], tmp);
        pconcat = operatorsrequired(v, a+1, n-1, 3);
        a[1] = tmp;
    }
    if (pconcat) return 3;
    if (pmult) return 2;
    if (pplus) return 2;
    return 0;
}

void aoc202407(char *data, size_t len) {
    (void)len; // unused argument
    unsigned long long calibrationtotal = 0, calibration3total = 0;
    char *line = strtok(data, "\n");
    unsigned long long number[50], nnumber;