diff options
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); } |