summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-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);
 }