summary refs log tree commit diff homepage
path: root/2020/day13.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-13 17:10:01 -0500
committerJune McEnroe <june@causal.agency>2020-12-13 17:10:01 -0500
commit128617566fd0d04009e74ec55d197cd41d284c49 (patch)
treef157b522c44cfc1faa6cefd32a0acc4a93494f03 /2020/day13.c
parentSolve day 13 part 1 (diff)
downloadaoc-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.
Diffstat (limited to '2020/day13.c')
-rw-r--r--2020/day13.c10
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);
 }