-
Notifications
You must be signed in to change notification settings - Fork 3
/
day03.py
43 lines (35 loc) · 1.02 KB
/
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
40
41
42
43
#!/usr/bin/env python
"""
Advent Of Code 2015 Day 3
https://adventofcode.com/2015/day/3
"""
from collections import defaultdict
from aoc.parsers import first_line
def count_visited(directions: str, num_santas: int):
deltas = {
">": complex(1, 0),
"<": complex(-1, 0),
"^": complex(0, 1),
"v": complex(0, -1),
}
locs = [complex(0, 0)] * num_santas
seen = defaultdict(int)
seen[locs[0]] += 1
i = 0
for char in directions:
locs[i] += deltas[char]
seen[locs[i]] += 1
i = (i + 1) % num_santas
return len(seen.keys())
class Day03:
""" AoC 2015 Day 03 """
@staticmethod
def part1(filename: str) -> int:
""" Given a filename, solve 2015 day 03 part 1 """
directions = first_line(filename)
return count_visited(directions, 1)
@staticmethod
def part2(filename: str) -> int:
""" Given a filename, solve 2015 day 21 part 2 """
directions = first_line(filename)
return count_visited(directions, 2)