diff options
author | June McEnroe <june@causal.agency> | 2021-12-04 18:10:18 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-12-04 18:10:18 -0500 |
commit | 64cab0a735de8d8faaadf1dcce86444fed22a395 (patch) | |
tree | 4afc4a20f803389e1918fec85cdf5f67747d2310 /2021/day04.c | |
parent | Solve day 4 part 1 (diff) | |
download | aoc-64cab0a735de8d8faaadf1dcce86444fed22a395.tar.gz aoc-64cab0a735de8d8faaadf1dcce86444fed22a395.zip |
Solve day 4 part 2
This is hilariously bad.
Diffstat (limited to '2021/day04.c')
-rw-r--r-- | 2021/day04.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/2021/day04.c b/2021/day04.c index 88bf80f..c414f81 100644 --- a/2021/day04.c +++ b/2021/day04.c @@ -50,4 +50,25 @@ int main(void) { if (!(boards[w].mark & (1 << i))) sum += boards[w].nums[i]; } printf("%d\n", sum * num); + for (; i < n; ++i) { + for (int j = 0; j < len; ++j) { + for (int k = 0; k < 25; ++k) { + if (boards[j].nums[k] == nums[i]) { + int won = win(&boards[j]); + boards[j].mark |= 1 << k; + if (!won && win(&boards[j])) { + w = j; + num = nums[i]; + sum = 0; + for (int i = 0; i < 25; ++i) { + if (!(boards[w].mark & (1 << i))) { + sum += boards[w].nums[i]; + } + } + } + } + } + } + } + printf("%d\n", sum * num); } |