summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-13 00:13:32 -0500
committerJune McEnroe <june@causal.agency>2020-12-13 00:40:09 -0500
commitbed2dd20f640ccd4eab0a8ffbd5052f3593357b5 (patch)
treedae8405902a0af2b6ee95b774d54ecd690b38cbd
parentSolve day 12 part 2 (diff)
downloadaoc-bed2dd20f640ccd4eab0a8ffbd5052f3593357b5.tar.gz
aoc-bed2dd20f640ccd4eab0a8ffbd5052f3593357b5.zip
Solve day 13 part 1
-rw-r--r--2020/day13.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/2020/day13.c b/2020/day13.c
new file mode 100644
index 0000000..f8c0665
--- /dev/null
+++ b/2020/day13.c
@@ -0,0 +1,26 @@
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+int main(void) {
+	int earliest = 0;
+	scanf("%d\n", &earliest);
+	int buses[128] = {0};
+	int len = 0;
+	for (;;) {
+		int n = scanf("%d,", &buses[len]);
+		if (!n) n = scanf("x,");
+		if (n < 0) break;
+		len++;
+	}
+	int min = INT_MAX;
+	int bus = 0;
+	for (int i = 0; i < len; ++i) {
+		if (!buses[i]) continue;
+		int wait = (earliest / buses[i] + 1) * buses[i] - earliest;
+		if (wait < min) {
+			min = wait;
+			bus = buses[i];
+		}
+	}
+	printf("%d\n", bus * min);
+}
td>Add Conversations With FriendsJune McEnroe 2022-07-30Add Normal PeopleJune McEnroe 2022-07-26Rewrite glitch from new pngoJune McEnroe 2022-07-26Update Care with time-to-ID and piercingsJune McEnroe 2022-07-26Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe 2022-07-03Add The Bone Shard EmperorJune McEnroe 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe