summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-07 13:20:47 -0500
committerJune McEnroe <june@causal.agency>2018-12-07 13:20:47 -0500
commit21a9629c97ab46886673888484be895597e9a459 (patch)
tree73e1826dbbf16384331dd10146fd20cc55ffa136
parentSolve day 7 part 1 (diff)
downloadaoc-21a9629c97ab46886673888484be895597e9a459.tar.gz
aoc-21a9629c97ab46886673888484be895597e9a459.zip
Solve day 7 part 2
-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);
 }