aoc_omni/c/2015/1/problem.c

27 lines
476 B
C
Raw Normal View History

2023-12-19 14:42:49 -05:00
#include <stdio.h>
int main() {
FILE* input = fopen("../data/2015/1/input.txt", "r");
char c;
int floor = 0;
while (fread(&c, 1, 1, input) > 0) {
if (c == '(') floor++;
else if(c == ')') floor--;
}
printf("Part 1: %d\n", floor);
floor = 0;
int steps = 0;
rewind(input);
while (fread(&c, 1, 1, input) > 0) {
if (c == '(') floor++;
else if(c == ')') floor--;
steps++;
if (floor < 0) break;
}
printf("Part 2: %d\n", steps);
}