From 85a2a9b23af21f1fedd7060e1ad2817d856d1c61 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 18 Dec 2020 00:32:54 -0500 Subject: Solve day 18 part 1 --- 2020/day18.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2020/day18.c diff --git a/2020/day18.c b/2020/day18.c new file mode 100644 index 0000000..337f107 --- /dev/null +++ b/2020/day18.c @@ -0,0 +1,27 @@ +#include +#include +static long parse(void) { + long result = 0; + char op = '+'; + for (char ch; EOF != (ch = getchar());) { + long val = 0; + switch (ch) { + break; case ' ': continue; + break; case '(': val = parse(); + break; case ')': return result; + break; case '\n': return result; + break; case '0' ... '9': val = ch - '0'; + break; default: op = ch; continue; + } + switch (op) { + break; case '+': result += val; + break; case '*': result *= val; + } + } + return result; +} +int main(void) { + long sum = 0; + for (long line; (line = parse()); sum += line); + printf("%ld\n", sum); +} -- cgit 1.4.1 de770daf93c2269e02b1f9ce3386e0ec85c05684'>refs log tree commit diff
Commit message (Collapse)Author
2020-06-16Add LC_COLLATE=C to ls aliasJune McEnroe
2020-06-11Fix pbd for neovimJune McEnroe
At some point neovim started setting argv[0] to the absolute path for some reason.
2020-06-11Alias sudo=doas if availableJune McEnroe
2020-06-11Add all VMs to ssh configJune McEnroe
2020-06-08Add additional permission for linking with LibreSSLJune McEnroe
https://www.gnu.org/licenses/gpl-faq.en.html#GPLIncompatibleLibs
2020-06-08Replace __DECONST with regular castsJune McEnroe
sed -E 's/__DECONST[(]([^,]+), ([^)]+)[)]/(\1)(\2)/'
2020-06-08Replace __printflike with __attribute__((format(printf, ...)))June McEnroe
sed -E 's/__printf0?like[(]([^,]+), ([^)]+)[)]/__attribute__((format(printf, \1, \2)))/'
2020-06-08Replace __dead2 with __attribute__((noreturn))June McEnroe
sed 's/__dead2/__attribute__((noreturn))/'
2020-06-08Replace __FBSDID macros with commentsJune McEnroe
sed -E 's|__FBSDID[(]"([^"]+)"[)];|/* \1 */|'
2020-06-08Remove reference to FreeBSD-specific libedit hackJune McEnroe
Newer versions of libedit have sane tab-complete now without FreeBSD's hacks, and in fact the hack is gone in FreeBSD-CURRENT. I'm still a little confused why binding this weird function is necessary at all, but at least it exists everywhere, I guess.
2020-06-08Prefix mandoc with exec in about-filterJune McEnroe
2020-06-07Remove mktemp options from mkbuiltins, mktokensJune McEnroe
Why even?
2020-06-07Cast z_stream fields to size_tJune McEnroe
In the version of zlib in OpenBSD, these fields are of type off_t, which is signed (why?), rather than uLong.
2020-06-07Call static_assert by _Static_assertJune McEnroe
OpenBSD doesn't #define static_assert in assert.h and _Static_assert is its real name I guess so why not?
2020-06-07Add OpenBSD to install.shJune McEnroe
Straightforward.
2020-06-03Add The Song of AchillesJune McEnroe
2020-06-01Allow redirecting input in everJune McEnroe
2020-05-31Add %c conversion to c scriptJune McEnroe
2020-05-31Add c script to READMEJune McEnroe
2020-05-31Add c scriptJune McEnroe
2020-05-31Update mdoc source URLsJune McEnroe
2020-05-26Remove unfinished PSF fontsJune McEnroe