Day 1 - Advent of Code 2015

Working solutions for the day 1 puzzles.

Part One

""" day_01_01.py """

# usage: python3 day_01_01.py < input

import sys


floor = 0
for instruction in sys.stdin.read():
    if instruction == '(':
        floor += 1
    elif instruction == ')':
        floor -= 1
print(floor)

Part Two

""" day_01_02.py """

# usage: python3 day_01_02.py < input

import sys


index = None
floor = 0
for index, instruction in enumerate(sys.stdin.read()):
    if instruction == '(':
        floor += 1
    elif instruction == ')':
        floor -= 1
    if floor == -1:
        break
if index is not None:
    print(index + 1)