diff options
author | June McEnroe <june@causal.agency> | 2018-12-07 13:20:47 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-11-22 00:14:25 -0500 |
commit | 8a0bbb7531045b9176bb8b9c048271104493a9ec (patch) | |
tree | 1deb051b08ab8153e2b62cb67613926627b80ded | |
parent | Solve day 7 part 1 (diff) | |
download | aoc-8a0bbb7531045b9176bb8b9c048271104493a9ec.tar.gz aoc-8a0bbb7531045b9176bb8b9c048271104493a9ec.zip |
Solve day 7 part 2
-rw-r--r-- | 2018/day07.c | 29 |
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); } |