2015-12-03 - Perfectly Spherical Houses in a Vacuum
(original .ipynb)puzzle_input_str = open("./puzzle_input/day3.txt").read() directions = { "^": (-1, 0), "v": ( 1, 0), "<": ( 0, -1), ">": ( 0, 1), } def part_one(input_str): x, y = 0, 0 houses = set() houses.add((0, 0)) for instr in input_str: dx, dy = directions[instr] x += dx y += dy houses.add((x,y)) return len(houses) assert 2 == part_one(">") assert 4 == part_one("^>v<") assert 2 == part_one("^v^v^v^v^v") print("part one:", part_one(puzzle_input_str))
part one: 2081
def part_two(input_str): santa_positions = [ (0, 0), (0, 0) ] houses = set() houses.add((0, 0)) for i, instr in enumerate(input_str): santa = i % 2 dx, dy = directions[instr] x, y = santa_positions[santa] houses.add((x + dx, y + dy)) santa_positions[santa] = (x + dx, y + dy) return len(houses) assert 3 == part_two("^v") assert 3 == part_two("^>v<") assert 11 == part_two("^v^v^v^v^v") print("part_two:", part_two(puzzle_input_str))
part_two: 2341