NORTH = "^" SOUTH = "v" WEST = "<" EAST = ">" def move(pos, d): if d == NORTH: pos[1] += 1 if d == SOUTH: pos[1] -= 1 if d == WEST: pos[0] -= 1 if d == EAST: pos[0] += 1 def visit(s): pos = [0,0] visits = set() visits.add((pos[0], pos[1])) for c in s: move(pos, c) visits.add((pos[0], pos[1])) return len(visits) def test(): assert visit(">") == 2 assert visit("^>v<") == 4 assert visit("^v^v^v^v^v") == 2 def solution(): with open("in1") as puzzle: l = puzzle.read() return visit(l) if __name__ == "__main__": print(f"Houses: {solution()}")