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