#Skip to menu

Day 3, Year 2015: Perfectly Spherical Houses in a Vacuum

First read the problem description.
def count_houses(it, santas=1):
    positions = []
    for _ in range(santas):
        positions.append([0,0])

    houses = set()
    turn = 0
    for pos in positions:
        houses.add(tuple(pos))

    for ch in it:
        if ch == '^':
            positions[turn][1] += 1
        elif ch == 'v':
            positions[turn][1] -= 1
        elif ch == '>':
            positions[turn][0] += 1
        elif ch == '<':
            positions[turn][0] -= 1
        else:
            continue
        houses.add(tuple(positions[turn]))
        turn = (turn + 1) % santas
    
    return len(houses)
import import_ipynb
import helper
s = helper.read_file('2015_3.txt')
assert count_houses('>') == 2
assert count_houses('^>v<') == 4
assert count_houses('^v^v^v^v^v') == 2
count_houses(s)
2592
assert count_houses('^v', 2) == 3
assert count_houses('^>v<', 2) == 3
assert count_houses('^v^v^v^v^v', 2) == 11
count_houses(s, 2)
2360

Source code of the solution(s):