diff options
author | June McEnroe <june@causal.agency> | 2020-12-13 17:10:01 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-13 17:10:01 -0500 |
commit | 128617566fd0d04009e74ec55d197cd41d284c49 (patch) | |
tree | f157b522c44cfc1faa6cefd32a0acc4a93494f03 | |
parent | Solve day 13 part 1 (diff) | |
download | aoc-128617566fd0d04009e74ec55d197cd41d284c49.tar.gz aoc-128617566fd0d04009e74ec55d197cd41d284c49.zip |
Spoiled solve day 13 part 2
I think I might've been close to coming up with this at some point but everyone was acting like it was impossible without knowing "Chinese Remainder Theorem" and I just got pissed off.
-rw-r--r-- | 2020/day13.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/2020/day13.c b/2020/day13.c index f8c0665..a0e8c98 100644 --- a/2020/day13.c +++ b/2020/day13.c @@ -23,4 +23,14 @@ int main(void) { } } printf("%d\n", bus * min); + long t = 0; + long x = buses[0]; + for (int i = 1; i < len; ++i) { + if (!buses[i]) continue; + while ((t + i) % buses[i]) { + t += x; + } + x *= buses[i]; + } + printf("%ld\n", t); } |