From ee31c9b7002c6dd9ea824007611a4899aae9faea Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 9 Dec 2020 00:28:32 -0500 Subject: Solve day 9 part 2 --- 2020/day09.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to '2020') diff --git a/2020/day09.c b/2020/day09.c index f67fb4e..5b5d5d4 100644 --- a/2020/day09.c +++ b/2020/day09.c @@ -1,3 +1,4 @@ +#include #include #include enum { Cap = 25 }; @@ -17,12 +18,31 @@ static int valid(int x) { } int main(void) { int x; + int list[1024]; + int len = 0; while (EOF != scanf("%d\n", &x)) { - if (index < Cap || valid(x)) { - push(x); + list[len++] = x; + } + int invalid = 0; + for (int i = 0; i < len; ++i) { + if (index < Cap || valid(list[i])) { + push(list[i]); } else { - printf("%d\n", x); + printf("%d\n", list[i]); + invalid = list[i]; break; } } + for (int i = 0; i < len; ++i) { + int sum = 0, min = INT_MAX, max = INT_MIN; + for (int j = i; j < len; ++j) { + if (list[j] < min) min = list[j]; + if (list[j] > max) max = list[j]; + sum += list[j]; + if (sum == invalid) { + printf("%d\n", min + max); + return 0; + } + } + } } -- cgit 1.4.1 efs log tree commit diff
Commit message (Expand)Author
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