Advent of Code

Diff
Login

Diff

Differences From Artifact [98d4a70597]:

To Artifact [5ec424337a]:


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        switch (operatorsrequired(testvalue, number, nnumber, 0)) {
            default: break;
            case 2: calibrationtotal += testvalue;
                    __attribute__((fallthrough));
            case 3: calibration3total += testvalue;
                    break;
        }
        #if 0
        if (canbetrue(testvalue, number, nnumber)) {
            calibrationtotal += testvalue;
        }
        if (canbetrue3(testvalue, number, nnumber)) {
            calibration3total += testvalue;
        }
        #endif
        line = strtok(NULL, "\n");
    }
    printf("The calibration total is {%llu}.\n", calibrationtotal);
    printf("The calibration total with three operators is {%llu}.\n", calibration3total);
}

/* === aoc202406 =======================================================







<
<
<
<
<
<
<
<







58
59
60
61
62
63
64








65
66
67
68
69
70
71
        switch (operatorsrequired(testvalue, number, nnumber, 0)) {
            default: break;
            case 2: calibrationtotal += testvalue;
                    __attribute__((fallthrough));
            case 3: calibration3total += testvalue;
                    break;
        }








        line = strtok(NULL, "\n");
    }
    printf("The calibration total is {%llu}.\n", calibrationtotal);
    printf("The calibration total with three operators is {%llu}.\n", calibration3total);
}

/* === aoc202406 =======================================================
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    return (tmp == 15);
}

void aoc202404(char *data, size_t len) {
    (void)len; // unused argument
    // assume data is well-formatted and has the same number of rows and columns
    unsigned size = strchr(data, '\n') - data;
    #if 0 // check assumption
    printf("data has %u cols, first three rows start with %c%c, %c%c, and %c%c.\n",
          size, data[0], data[1],
          data[1*(size+1)], data[1*(size+1)+1],
          data[2*(size+1)], data[2*(size+1)+1]);
    printf("ends with %c%c.\n", data[(size-1)*(size+1) + size-2], data[(size-1)*(size+1)+size-1]);
    printf("data has %u cols, first three rows start with %c%c, %c%c, and %c%c.\n",
          size, data[linearize2d(size+1, 0, 0)], data[linearize2d(size+1, 0, 1)],
          data[linearize2d(size+1, 1, 0)], data[linearize2d(size+1, 1, 1)],
          data[linearize2d(size+1, 2, 0)], data[linearize2d(size+1, 2, 1)]);
    printf("ends with %c%c.\n", data[linearize2d(size+1, size-1, size-2)], data[linearize2d(size+1, size-1, size-1)]);
    #endif
    unsigned xmascount = 0, Xmascount = 0;
    for (unsigned row = 0; row < size; row++) {
        for (unsigned col = 0; col < size; col++) {
            xmascount += xmasat(data, size, row, col);
            if ((1 <= row) && (row < size - 1) && (1 <= col) && (col < size - 1)) {
                if (Xmasat(data, size, row, col)) Xmascount++;
            }







<
<
<
<
<
<
<
<
<
<
<
<







274
275
276
277
278
279
280












281
282
283
284
285
286
287
    return (tmp == 15);
}

void aoc202404(char *data, size_t len) {
    (void)len; // unused argument
    // assume data is well-formatted and has the same number of rows and columns
    unsigned size = strchr(data, '\n') - data;












    unsigned xmascount = 0, Xmascount = 0;
    for (unsigned row = 0; row < size; row++) {
        for (unsigned col = 0; col < size; col++) {
            xmascount += xmasat(data, size, row, col);
            if ((1 <= row) && (row < size - 1) && (1 <= col) && (col < size - 1)) {
                if (Xmasat(data, size, row, col)) Xmascount++;
            }