From 64cab0a735de8d8faaadf1dcce86444fed22a395 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 4 Dec 2021 18:10:18 -0500 Subject: Solve day 4 part 2 This is hilariously bad. --- 2021/day04.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to '2021/day04.c') 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); } -- cgit 1.4.1