file = [i.rstrip() for i in open("input").readlines()] class House: def __init__(self, x, y): self.x = x self.y = y self.count = 0 def inc(self): self.count = 1 class HouseHolder: def __init__(self): self.x = 0 self.y = 0 self.houses = [] self._update() def _update(self): found = False for i in self.houses: if i.x == self.x and i.y == self.y: i.inc() found = True break if not found: self.houses.append(House(self.x, self.y)) self.houses[-1].inc() def up(self): self.y += 1 self._update() def down(self): self.y -= 1 self._update() def right(self): self.x += 1 self._update() def left(self): self.x -= 1 self._update() def getHouseData(self): return len(self.houses) h = HouseHolder() hr = HouseHolder() flip = False sel = { False: h, True: hr } for i in file[0]: if i == ">": sel[flip].right() if i == "<": sel[flip].left() if i == "^": sel[flip].up() if i == "v": sel[flip].down() flip = not flip bothhouses = h.houses + hr.houses ret = [] for i in bothhouses: dup = False for j in ret: if i.x == j.x and i.y == j.y: dup = True if not dup: ret.append(i) print(len(ret))