day 11 part 1
[aoc_eblake.git] / 2017 / advent9.c
blobc1e933acb2197c117547489cba589d912089d344
1 #define _GNU_SOURCE 1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 int main(void)
9 int depth = 0;
10 int score = 0;
11 int garbage = 0;
12 int count = 0;
13 int c;
14 while ((c = getchar ()) >= 0)
15 if (garbage) {
16 if (c == '!')
17 getchar ();
18 else if (c == '>')
19 garbage = 0;
20 else
21 count++;
22 } else {
23 if (c == '{')
24 score += ++depth;
25 else if (c == '}')
26 depth--;
27 else if (c == '<')
28 garbage = 1;
30 if (depth)
31 printf("oops\n");
32 printf("score=%d garbage=%d\n", score, count);
33 return 0;