C (lovely)
This commit is contained in:
parent
82409ba1df
commit
dc3085b216
1
c/.gitignore
vendored
Normal file
1
c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
problem
|
26
c/2015/1/problem.c
Normal file
26
c/2015/1/problem.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user