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);
+}
356f&follow=1'>List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe neovim is laggy as hell in my OpenBSD VM, so I switched to vi so I could type without getting frustrated. 2021-01-09Add c -t flag to print expression typeJune McEnroe Also add missing float case. 2021-01-05Update taglineJune McEnroe