summary refs log tree commit diff homepage
path: root/2020/day18.c
blob: 337f107b08c1e6e822e7d7de9407ed5d980b7af0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
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);
}
85be4908&follow=1'>Add -x flag to titleJune McEnroe 2019-09-07Ignore SIGPIPE in relayJune McEnroe 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe 2019-09-05Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe