summary refs log tree commit diff homepage
path: root/2018
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-07 13:20:47 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commit8a0bbb7531045b9176bb8b9c048271104493a9ec (patch)
tree1deb051b08ab8153e2b62cb67613926627b80ded /2018
parentSolve day 7 part 1 (diff)
downloadaoc-8a0bbb7531045b9176bb8b9c048271104493a9ec.tar.gz
aoc-8a0bbb7531045b9176bb8b9c048271104493a9ec.zip
Solve day 7 part 2
Diffstat (limited to '2018')
-rw-r--r--2018/day07.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/2018/day07.c b/2018/day07.c
index 43dd786..092ce99 100644
--- a/2018/day07.c
+++ b/2018/day07.c
@@ -24,4 +24,33 @@ int main() {
 		}
 	}
 	printf("\n");
+
+	uint time = 0;
+	uint prog = 0;
+	uint done = 0;
+	struct {
+		uint step;
+		uint time;
+	} work[5] = {0};
+	while (done != (1 << 26) - 1) {
+		for (uint i = 0; i < 26; ++i) {
+			if (done & (1 << i)) continue;
+			if (prog & (1 << i)) continue;
+			if ((deps[i] & done) != deps[i]) continue;
+			for (uint w = 0; w < 5; ++w) {
+				if (work[w].time) continue;
+				work[w].step = (1 << i);
+				work[w].time = 61 + i;
+				prog |= work[w].step;
+				break;
+			}
+		}
+		for (uint w = 0; w < 5; ++w) {
+			if (work[w].time && --work[w].time) continue;
+			done |= work[w].step;
+			prog &= ~work[w].step;
+		}
+		time++;
+	}
+	printf("%u\n", time);
 }
9d0e5c8aa276c5456b42c6721e&follow=1'>Scroll 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