aboutsummaryrefslogtreecommitdiff
path: root/2015/01/puzzles.c
blob: 6690a64ed641da1cc0274647a1904a81d4ec5047 (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
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
	int c;
	FILE *fp = fopen("input", "r");

	register int floor = 0;
	for (register unsigned int i = 1; (c = fgetc(fp)) != EOF; i++) {
		floor += (c == '(') ? 1 : -1;
#ifdef PART2
		if (floor == -1) {
			printf("%u\n", i);
			return EXIT_SUCCESS;
		}
#endif
	}

	fclose(fp);
	printf("%d\n", floor);

	return EXIT_SUCCESS;
}