From 2cca6cddb4eda61a35ae7e976cd433acc0e58e4c Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Wed, 2 Dec 2015 12:36:29 +0000 Subject: Added second parts to days 1 and 2 --- day1.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'day1.c') diff --git a/day1.c b/day1.c index 365e525..dbd188d 100644 --- a/day1.c +++ b/day1.c @@ -1,8 +1,9 @@ #include 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; } -- cgit v1.2.1