r/programming • • Dec 01 '15

Daily programming puzzles at Advent of Code

http://adventofcode.com/
324 Upvotes

179 comments sorted by

View all comments

1

u/Scruff3y Dec 01 '15

In C:

#include <stdio.h>
int main(void)
{
	char current;
	int santasFloor = 0;
	int counter = 1;

	while((current = getchar()) != EOF){
 		santasFloor += ((current == '(')*2) -1;
		if(santasFloor == -1){
			printf("Santa first enters the basement at instruction %d\n", counter);
		}
		counter++;
	}

	printf("The instructions point to floor %d\n", santasFloor);
	
	return 0;
}

Yes, I know it prints every time he enters the basement.