Sean McLemon | Advent of Code

Home | Czech | Blog | GitHub | Advent Of Code | Notes


2015-12-01 - Not Quite Lisp

(original .ipynb)

Puzzle input is a sequence of '(' and ')' characters. Part one involves interpreting them as instructions to move up - '(' - or down - ')' floors in a building and seeing where you end up if you follow these instructions. Part two involves following the instructions but finding out the first step that causes you to enter the basement (floor -1)

puzzle_input_str = open("./puzzle_input/day1.txt").read()


def part_one(input_str):
    return sum(map(lambda c: 1 if c =="(" else -1, input_str))

print("part one:", part_one(puzzle_input_str))
part one: 280
def part_two(input_str):
    floor = 0
    for i, c in enumerate(input_str):
        if floor == -1:
            return i
        floor += 1 if c =="(" else -1
    return -1
    
print("part two:", part_two(puzzle_input_str))
part two: 1797