Overview
Comment: | 202404 1st star |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
0fa98a442cacdbd66c425ecd2c2cdaef |
User & Date: | nnz on 2024-12-04 10:51:54 |
Original Comment: | part 1 completed (correct on the first run) |
Other Links: | manifest | tags |
Context
2024-12-04
| ||
11:56 | 202404 2nd star check-in: 70a16d5d32 user: nnz tags: trunk | |
10:51 | 202404 1st star check-in: 0fa98a442c user: nnz tags: trunk | |
10:01 | first check check-in: 6802a94662 user: nnz tags: trunk | |
Changes
Modified aoc2024.c from [9ff67230c6] to [3d58482423].
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - + + + + + + + + + + + + + + + + + | #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 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) { 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[rcmap(size, (unsigned)((int)row + drow), (unsigned)((int)col + dcol))] != 'M') return false; if (data[rcmap(size, (unsigned)((int)row + 2*drow), (unsigned)((int)col + 2*dcol))] != 'A') return false; if (data[rcmap(size, (unsigned)((int)row + 3*drow), (unsigned)((int)col + 3*dcol))] != 'S') return false; } else { return false; } return true; } static unsigned xmasat(char *data, unsigned size, unsigned row, unsigned col) { unsigned finds = 0; if (data[rcmap(size, row, col)] != 'X') return 0; if (masat(data, size, row, col, -1, -1)) finds++; if (masat(data, size, row, col, -1, 0)) finds++; if (masat(data, size, row, col, -1, +1)) finds++; if (masat(data, size, row, col, 0, -1)) finds++; if (masat(data, size, row, col, 0, +1)) finds++; if (masat(data, size, row, col, +1, -1)) finds++; if (masat(data, size, row, col, +1, 0)) finds++; if (masat(data, size, row, col, +1, +1)) finds++; return finds; } 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 |
︙ |