advent/2015/3/sol.py
2022-11-06 13:55:53 -06:00

63 lines
1.1 KiB
Python

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()
for i in file[0]:
if i == ">":
h.right()
if i == "<":
h.left()
if i == "^":
h.up()
if i == "v":
h.down()
print(h.getHouseData())