blob: 8d5854eb88d054e2e9ad7db1cbd5822db0be0ca9 (
plain) (
blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#!/usr/bin/env python
from collections import defaultdict
with open('day3.txt') as data:
directions = data.read().strip()
# part 1
x, y = 0, 0
houses = defaultdict(int)
houses[(x, y)] = 1
for direction in directions:
match direction:
case '^':
y += 1
case 'v':
y -= 1
case '>':
x += 1
case '<':
x -= 1
houses[(x, y)] += 1
print(len(houses))
# part 2
santaX, santaY, roboX, roboY = 0, 0, 0, 0
houses = defaultdict(int)
houses[(0, 0)] = 2
isSanta = True
for direction in directions:
if isSanta:
match direction:
case '^':
santaY += 1
case 'v':
santaY -= 1
case '>':
santaX += 1
case '<':
santaX -= 1
houses[(santaX, santaY)] += 1
else:
match direction:
case '^':
roboY += 1
case 'v':
roboY -= 1
case '>':
roboX += 1
case '<':
roboX -= 1
houses[(roboX, roboY)] += 1
isSanta = not isSanta
print(len(houses))
|