aoc/src/2015/01.c

30 lines
403 B
C
Raw Normal View History

2021-07-14 13:50:33 -07:00
#include <stdio.h>
2021-09-01 15:08:54 -07:00
#include <stdlib.h>
2021-09-01 15:39:09 -07:00
#include <string.h>
2021-07-14 13:50:33 -07:00
#include "input.h"
void advent2015day01(void) {
2021-09-01 15:08:54 -07:00
char *input = get_input("input/2015/01");
2021-09-01 15:39:09 -07:00
char *c = input;
int f = 0, b = 0, s = 1;
while (*c != '\0') {
if (*c == '(') {
++f;
} else {
--f;
}
if (f == -1 && b == 0) {
b = s;
}
++c;
++s;
}
printf("%d\n%d\n", f, b);
2021-09-01 15:08:54 -07:00
free(input);
2021-07-14 13:50:33 -07:00
}