summary refs log tree commit diff homepage
path: root/2018
diff options
context:
space:
mode:
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);
 }
5f639f97fd4613b3edbf83fa&follow=1'>Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe 2022-02-18Implement new line editing "library"June McEnroe 2022-02-18Simplify cursor positioning in inputJune McEnroe 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe