summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-04 18:10:18 -0500
committerJune McEnroe <june@causal.agency>2021-12-04 18:10:18 -0500
commit64cab0a735de8d8faaadf1dcce86444fed22a395 (patch)
tree4afc4a20f803389e1918fec85cdf5f67747d2310
parentSolve day 4 part 1 (diff)
downloadaoc-64cab0a735de8d8faaadf1dcce86444fed22a395.tar.gz
aoc-64cab0a735de8d8faaadf1dcce86444fed22a395.zip
Solve day 4 part 2
This is hilariously bad.
Diffstat (limited to '')
-rw-r--r--2021/day04.c21
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);
 }
5 17:00:28 -0500'>2019-02-25Output raw to standard error if it is not a terminalJune McEnroe 2019-02-25Update tag colorsJune McEnroe 2019-02-25Add color to tagsJune McEnroe 2019-02-25Remove tag X macros againJune McEnroe 2019-02-25Add M-a to switch to hot or unread windowJune McEnroe 2019-02-25Refactor uiReadJune McEnroe 2019-02-24Scroll by full pages with PageUp/PageDownJune McEnroe 2019-02-23Clarify /window documentationJune McEnroe 2019-02-23Use first word of params in input commandsJune McEnroe 2019-02-23Add C-n and C-p key bindings to switch windowsJune McEnroe 2019-02-23Change example command to join #ascii.town on freenodeJune McEnroe 2019-02-23Call def_prog_mode after termNoFlowJune McEnroe 2019-02-22Move IRC formatting reset to C-sJune McEnroe 2019-02-22Disable terminal flow controlJune McEnroe 2019-02-22Bind up and down arrows to scrollJune McEnroe 2019-02-22Remove topic TODOJune McEnroe 2019-02-22Add /znc commandJune McEnroe 2019-02-22Update status line after scrolling and term eventsJune McEnroe 2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe 2019-02-21Replace "view" with "window"June McEnroe 2019-02-21Remove ROT13June McEnroe 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe