aboutsummaryrefslogtreecommitdiff
path: root/day1/day1.c
diff options
context:
space:
mode:
authorNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-12-07 15:16:10 +0000
committerNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-12-07 15:16:10 +0000
commit09cbfeeca74e6b7ca9a9b5d49646c538b8a3f4ba (patch)
treed91f437cc4b676155b7c110b8da8c90995523771 /day1/day1.c
parent02d64d66b1e3c904b54c19ac2b5e9756d49959fb (diff)
Rearranged into folders, added makefile for convenience.
Diffstat (limited to 'day1/day1.c')
-rw-r--r--day1/day1.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/day1/day1.c b/day1/day1.c
new file mode 100644
index 0000000..dbd188d
--- /dev/null
+++ b/day1/day1.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int main() {
+ int ch, floor = 0, pos = 0, first_basement = 1;
+ while ((ch = getchar()) != EOF) {
+ pos += 1;
+ switch(ch) {
+ case '(':
+ floor += 1;
+ break;
+ case ')':
+ floor -= 1;
+ }
+ if (floor == -1 && first_basement) {
+ printf("In the basement at position: %d\n", pos);
+ first_basement = 0;
+ }
+ }
+ printf("Final floor: %d\n", floor);
+ return 0;
+}