-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday03.py
39 lines (34 loc) · 952 Bytes
/
day03.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from adventofcode import Day
class Day03(Day):
def __init__(self):
super().__init__(2015, 3)
@staticmethod
def get_houses(script):
x = 0
y = 0
houses = {(x, y)}
for direction in script:
match direction:
case '<':
x -= 1
case '>':
x += 1
case '^':
y -= 1
case 'v':
y += 1
houses.add((x, y))
return houses
def part01(self):
text = super()._part01_input()
return len(Day03.get_houses(text))
def part02(self):
text = super()._part01_input()
one = ""
two = ""
for i in range(0, len(text)):
if i % 2 == 0:
one += text[i]
else:
two += text[i]
return len(Day03.get_houses(one).union(Day03.get_houses(two)))