summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-05 02:03:16 -0500
committerJune McEnroe <june@causal.agency>2018-12-05 02:03:16 -0500
commit46acbdc81dfe75a83718d075d6e966d8e5eb4001 (patch)
treee10d34ba23ef23659539329e9888ed39e093b7f8
parentSolve day 5 part 1 (diff)
downloadaoc-46acbdc81dfe75a83718d075d6e966d8e5eb4001.tar.gz
aoc-46acbdc81dfe75a83718d075d6e966d8e5eb4001.zip
Solve day 5 part 2
It's slow but whatever.
Diffstat (limited to '')
-rw-r--r--2018/day05.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/2018/day05.c b/2018/day05.c
index 5cb9366..1a80e2a 100644
--- a/2018/day05.c
+++ b/2018/day05.c
@@ -3,9 +3,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-int main() {
-	char buf[50000];
-	size_t len = fread(buf, 1, sizeof(buf), stdin);
+static size_t react(char *buf, size_t len) {
 	for (size_t i = 0; i < len - 1; ++i) {
 		if (tolower(buf[i]) != tolower(buf[i + 1])) continue;
 		if (islower(buf[i]) == islower(buf[i + 1])) continue;
@@ -13,5 +11,27 @@ int main() {
 		memmove(&buf[i], &buf[i + 2], len - i);
 		i = (size_t)-1;
 	}
-	printf("%zu\n", len);
+	return len;
+}
+
+int main() {
+	char buf[50000];
+	size_t len = fread(buf, 1, sizeof(buf), stdin);
+
+	char buf1[50000];
+	memcpy(buf1, buf, len);
+	printf("%zu\n", react(buf1, len));
+
+	size_t min = len;
+	for (char x = 'a'; x <= 'z'; ++x) {
+		char buf2[50000];
+		size_t len2 = 0;
+		for (size_t i = 0; i < len; ++i) {
+			if (tolower(buf[i]) == x) continue;
+			buf2[len2++] = buf[i];
+		}
+		len2 = react(buf2, len2);
+		if (len2 < min) min = len2;
+	}
+	printf("%zu\n", min);
 }
ll&id=9a69869d392ca9ac9e2d845dec5f4dfecdbf3456&follow=1'>Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe 2018-09-13Rewrite UI againJune McEnroe 2018-09-12Add note about C-oJune McEnroe 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe