From 46acbdc81dfe75a83718d075d6e966d8e5eb4001 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 5 Dec 2018 02:03:16 -0500 Subject: Solve day 5 part 2 It's slow but whatever. --- 2018/day05.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to '2018') 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 #include -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); } -- cgit 1.4.1 log/scripts/sshd_config?h=vimode&follow=1'>log tree commit diff
Commit message (Expand)Author
2020-02-11Add .gz to chroot-man scriptJune McEnroe
2020-02-11Add -R restricted flagJune McEnroe
2020-02-11Add chroot targetJune McEnroe
2020-02-11Exit focus and paste modes on err exitJune McEnroe
2020-02-11Add startup GPLv3 note and URLJune McEnroe
2020-02-11Make sure -D_GNU_SOURCE ends up in CFLAGS on LinuxJune McEnroe
2020-02-11Add note about setting PKG_CONFIG_PATHJune McEnroe
2020-02-11Rename query ID on nick changeJune McEnroe
2020-02-11Call completeClear when closing a windowJune McEnroe
2020-02-11Don't insert color codes for non-mentionsJune McEnroe
2020-02-11Take first two words in colorMentionsJune McEnroe
2020-02-11Use time_t for save signatureJune McEnroe
2020-02-11Set self.nick to * initiallyJune McEnroe
2020-02-11Define ColorCap instead of hardcoding 100June McEnroe
2020-02-11Move hash to top of chat.hJune McEnroe
2020-02-11Move base64 out of chat.hJune McEnroe
2020-02-11Move XDG_SUBDIR out of chat.hJune McEnroe
2020-02-11Fix whois idle unit calculationJune McEnroe
2020-02-11Cast towupper to wchar_tJune McEnroe
2020-02-11Cast set but unused variables to voidJune McEnroe
2020-02-11Declare strlcatJune McEnroe
2020-02-11Check if VDSUSP existsJune McEnroe
2020-02-11Fix completeReplace iterationJune McEnroe
2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe
2020-02-11Remove legacy codeJune McEnroe
2020-02-11Add INSTALLING section to READMEJune McEnroe