adventofcode/2015/day01/day01.c

50 lines
798 B
C
Raw Permalink Normal View History

2018-03-15 17:00:30 +00:00
#include <stdio.h>
void part1() {
printf("Part 1\n");
int floor = 0;
char ch = getchar();
while(ch) {
if(ch == '\n') { break; }
if(ch == '(') {
floor++;
} else if(ch == ')') {
floor--;
}
ch = getchar();
}
printf("Final Floor: %d\n", floor);
}
void part2() {
printf("Part 2\n");
int floor = 0, step = 0;
char ch = getchar();
while(ch) {
step++;
if(ch == '\n') { break; }
if(ch == '(') {
floor++;
} else if(ch == ')') {
floor--;
}
if(floor < 0) {
break;
}
ch = getchar();
}
printf("Enter basement at: %d\n", step);
}
int main(int argc, char **argv) {
int doPart = 1;
if(argc > 1) { doPart = argv[1][0] - '0'; }
if(doPart == 1) {
part1();
} else {
part2();
}
return 0;
}