Overview
Comment: | 202405 -- structure for part 2 in place; time for a think |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
88be09eaef3f57549a975df604d531ce |
User & Date: | nnz on 2024-12-05 12:32:29 |
Other Links: | manifest | tags |
Context
2024-12-05
| ||
14:39 | 202405 -- new idea: count pages positions check-in: fccbd87615 user: nnz tags: trunk | |
12:32 | 202405 -- structure for part 2 in place; time for a think check-in: 88be09eaef user: nnz tags: trunk | |
12:15 | 202405 1st star check-in: a12cf534f9 user: nnz tags: trunk | |
Changes
Modified aoc2024.c from [6e28b1efce] to [f1c77ad8a8].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <ctype.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "aocdailies.h" #include "aocutils.h" static const unsigned *vfind(unsigned v, const unsigned *a, size_t n) { for (size_t k = 0; k < n; k++) { if (a[k] == v) return a + k; } return NULL; } | > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <ctype.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "aocdailies.h" #include "aocutils.h" static void reorder(unsigned *a, size_t na, unsigned (*r)[2], size_t nr) { } static const unsigned *vfind(unsigned v, const unsigned *a, size_t n) { for (size_t k = 0; k < n; k++) { if (a[k] == v) return a + k; } return NULL; } |
︙ | ︙ | |||
33 34 35 36 37 38 39 | char *err = line; for (;;) { update[nupdates++] = strtoul(err, &err, 10); if (*err == ',') err++; else break; } if (nupdates % 2 == 0) printf("even number of updates found!\n"); | | | > > > > > | > | > | 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 | char *err = line; for (;;) { update[nupdates++] = strtoul(err, &err, 10); if (*err == ',') err++; else break; } if (nupdates % 2 == 0) printf("even number of updates found!\n"); unsigned accum = update[nupdates / 2], accumsum2 = 0; for (size_t k = 0; k < npp; k++) { const unsigned *before = vfind(pagepair[k][0], update, nupdates); if (!before) continue; const unsigned *after = vfind(pagepair[k][1], update, nupdates); if (!after) continue; if (before > after) { accum = 0; // reorder `update` according to `pagepair` reorder(update, nupdates, pagepair, npp); accumsum2 += update[nupdates / 2]; break; } } 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); } 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) { |
︙ | ︙ |