aboutsummaryrefslogtreecommitdiff
path: root/day1.c
diff options
context:
space:
mode:
Diffstat (limited to 'day1.c')
-rw-r--r--day1.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/day1.c b/day1.c
index 365e525..dbd188d 100644
--- a/day1.c
+++ b/day1.c
@@ -1,8 +1,9 @@
#include <stdio.h>
int main() {
- int ch, floor = 0;
+ int ch, floor = 0, pos = 0, first_basement = 1;
while ((ch = getchar()) != EOF) {
+ pos += 1;
switch(ch) {
case '(':
floor += 1;
@@ -10,7 +11,11 @@ int main() {
case ')':
floor -= 1;
}
+ if (floor == -1 && first_basement) {
+ printf("In the basement at position: %d\n", pos);
+ first_basement = 0;
+ }
}
- printf("%d\n", floor);
+ printf("Final floor: %d\n", floor);
return 0;
}