Overview
Comment: | 202406 2nd star (not pretty) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6538876b94409617762bcccf1812a9c9 |
User & Date: | nnz on 2024-12-06 16:28:38 |
Other Links: | manifest | tags |
Context
2024-12-06
| ||
16:32 | 202406 confirm 4 for repetitions check-in: fc7808669f user: nnz tags: trunk | |
16:28 | 202406 2nd star (not pretty) check-in: 6538876b94 user: nnz tags: trunk | |
13:54 | add space for terminating zero check-in: 16cb8577e3 user: nnz tags: trunk | |
Changes
Modified aoc2024.c from [02118ec5ef] to [4d7b1de895].
︙ | |||
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | case 'X': row_pos += deltarow; col_pos += deltacol; break; } } printf("The guard visits %u positions before leaving the area.\n", visited); // Part Two unsigned rowblock = 0, colblock = 0, positions = 0; int row_initial = (int)(linear_pos / size); int col_initial = (int)(linear_pos % size); for (;;) { strcpy(data, savedmap); if (data[linearize2d(size, (unsigned)rowblock, (unsigned)colblock)] == '.') { data[linearize2d(size, (unsigned)rowblock, (unsigned)colblock)] = '#'; // block it row_pos = row_initial; col_pos = col_initial; deltarow = -1; deltacol = 0; data[linearize2d(size, (unsigned)row_pos, (unsigned)col_pos)] = '1'; bool looping = false; while (!looping && validpos(size, row_pos + deltarow, col_pos + deltacol)) { switch (data[linearize2d(size, (unsigned)(row_pos+deltarow), (unsigned)(col_pos+deltacol))]) { default: puts("stepped on default"); exit(EXIT_FAILURE); case '#': if (data[linearize2d(size, (unsigned)(row_pos), (unsigned)(col_pos))] == '8') looping = true; rightturn(&deltarow, &deltacol); break; case '8': looping = true; break; case '.': data[linearize2d(size, (unsigned)(row_pos+deltarow), (unsigned)(col_pos+deltacol))] = '0'; /*fallthrough*/ case '1': case '2': case '3': case '4': case '5': case '6': case '7': data[linearize2d(size, (unsigned)(row_pos+deltarow), (unsigned)(col_pos+deltacol))]++; row_pos += deltarow; col_pos += deltacol; break; } } if (looping) positions++; } colblock++; if (colblock == size) { colblock = 0; rowblock++; if (rowblock == size) break; } } printf("You can obstruct %u different positions.\n", positions); free(savedmap); } /* === aoc202405 ======================================================= ===================================================================== */ static int ppcmp(unsigned a, unsigned b, unsigned (*r)[2], size_t nr) { |
︙ |