summary refs log tree commit diff homepage
path: root/2020
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
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')
-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);
 }
June McEnroe 2019-12-31Rewrite scoop(1) argument descriptionsJune McEnroe 2019-12-31Color both nicks in a changeJune McEnroe 2019-12-31Implement nick-colored outputJune McEnroe 2019-12-31Only enable highlighting on terminal outputJune McEnroe 2019-12-31Set up pager pipeJune McEnroe 2019-12-30Normalize date inputJune McEnroe Mostly this just allows the use of 'now'. 2019-12-30Add initial rough version of scoopJune McEnroe 2019-12-30Join with USING wherever possibleJune McEnroe 2019-12-30Add -D flag to prospective scoop manualJune McEnroe 2019-12-30Order results by ID in outer query in litterboxJune McEnroe 2019-12-30Use X macro for Type enumJune McEnroe 2019-12-30Remove scoop -ABCJune McEnroe I can almost get these to work with an inner and outer SQL query, but when contexts starts overlapping it becomes a disaster, so I'm leavin it out at least for now. 2019-12-30Add limit option for litterbox's search query interfaceJune McEnroe