Advent of Code 2015 Day 1

Author

Nathan Moore

— Day 1: Not Quite Lisp —

Santa is delivering presents in a large apartment building, but the lifts are a bit screwy.

To what floor do the instructions take Santa?

with open('data-2015-01.txt', 'r') as f:
    paren = f.read()

Simple enough, count the ups and downs.

paren.count('(') - paren.count(')')

# 137
138

— Part Two —

What is the position of the character that causes Santa to first enter the basement?

i = 0
santa = 0
p = list(paren)
while santa >= 0: 
    # move santa
    if p[i] == '(':
        santa += 1
    else:
        santa -= 1
    # increment
    i += 1
    
print(i)

# 1771
1771