73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
+
|
/* === aoc202406 =======================================================
Hmmm, I've done something like this already this year... on day 4
I need rcmap() moved to aocutils ... done; now it's called `linearize2d`
Part Two: brute force? It likely is faster than coming up with an algo
Let's go: save map, for every available position put in an obstacle,
loop around until some place is visited 4? times or area is exited
TODO remove linearize2d
===================================================================== */
static bool validpos(unsigned s, int r, int c) {
if (r < 0) return false;
if (c < 0) return false;
if ((unsigned)r >= s - 1) return false;
if ((unsigned)c >= s - 1) return false;
|
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
+
|
accumsum += accum;
} while ((line = strtok(NULL, "\n")) != NULL);
printf("The sum of middle update numbers is {%u}.\n", accumsum);
printf("The sum of middle update numbers for newly ordered updates is {%u}.\n", accumsum2);
}
/* === aoc202404 =======================================================
TODO remove linearize2d
===================================================================== */
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;
if ((0 <= maxrow) && (maxrow < (int)size) && (0 <= maxcol) && (maxcol < (int)size)) {
if (data[linearize2d(size+1, (unsigned)((int)row + drow), (unsigned)((int)col + dcol))] != 'M') return false;
|