aoc_omni/c/2015/1/problem.c

32 lines
550 B
C
Raw Normal View History

2023-12-19 14:42:49 -05:00
#include <stdio.h>
#include "../../lib/aoc.h"
2023-12-19 14:42:49 -05:00
int main() {
char *input = aoc_read_input();
2023-12-19 14:42:49 -05:00
int floor = 0;
int index = 0;
while (input[index] > 0) {
if (input[index] == '(') floor++;
else if(input[index] == ')') floor--;
index++;
2023-12-19 14:42:49 -05:00
}
printf("Part 1: %d\n", floor);
floor = 0;
int steps = 0;
index = 0;
2023-12-19 14:42:49 -05:00
while (input[index] > 0) {
if (input[index] == '(') floor++;
else if(input[index] == ')') floor--;
2023-12-19 14:42:49 -05:00
steps++;
if (floor < 0) break;
index++;
2023-12-19 14:42:49 -05:00
}
printf("Part 2: %d\n", steps);
free(input);
2023-12-19 14:42:49 -05:00
}