diff options
Diffstat (limited to '2020/18')
-rw-r--r-- | 2020/18/Makefile | 2 | ||||
-rw-r--r-- | 2020/18/solve.c | 20 |
2 files changed, 12 insertions, 10 deletions
diff --git a/2020/18/Makefile b/2020/18/Makefile index 9c7ab36..fc2ff1a 100644 --- a/2020/18/Makefile +++ b/2020/18/Makefile @@ -1,7 +1,7 @@ .PHONY: solve.c solve.o: solve.c - @gcc -g -Ofast $+ -o $@ + @gcc -Ofast $+ -o $@ clean: @rm -f *.o diff --git a/2020/18/solve.c b/2020/18/solve.c index 97d4ede..ae319fe 100644 --- a/2020/18/solve.c +++ b/2020/18/solve.c @@ -13,7 +13,7 @@ long add_or_mul(long *res, int num, int mul) return *res; } -long evil(char *str) +long evil(char *str, int prec) { long res = 0; int mul = 0, skip = 0, brace_cnt = 0; @@ -31,7 +31,7 @@ long evil(char *str) if (*p == ' ') { continue; } else if (*p == '(') { - add_or_mul(&res, evil(p + 1), mul); + add_or_mul(&res, evil(p + 1, prec), mul); skip = 1; } else if (*p == ')') { break; // That's why I don't use switch..case @@ -52,18 +52,20 @@ long part_one(FILE *fp) char *line = NULL; size_t len; - while (getline(&line, &len, fp) != -1) { - long a = evil(line); - printf("%lu\n", a); - res += a; - } + while (getline(&line, &len, fp) != -1) + res += evil(line, 0); return res; } -int part_two(FILE *fp) +long part_two(FILE *fp) { - int res = 0; + long res = 0; + + char *line = NULL; + size_t len; + while (getline(&line, &len, fp) != -1) + res += evil(line, 1); return res; } |