summaryrefslogtreecommitdiffstats
path: root/day16/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'day16/__init__.py')
-rw-r--r--day16/__init__.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/day16/__init__.py b/day16/__init__.py
new file mode 100644
index 0000000..ecf33c5
--- /dev/null
+++ b/day16/__init__.py
@@ -0,0 +1,60 @@
1# -*- coding: utf-8 -*-
2import re
3from abc import ABC
4from dataclasses import dataclass
5from typing import List, Iterator, Dict
6
7from aoc import BaseAssignment
8from aoc.mixins import AStarMixin
9
10
11@dataclass
12class Valve:
13 name: str
14 flow_rate: int
15 tunnels_to: List[str]
16
17 def __hash__(self):
18 return hash(self.name)
19
20
21valve_pattern = re.compile(
22 "Valve (\w+) has flow rate=(\d+); tunnels? leads? to valves? (.*)"
23)
24
25
26class Assignment(BaseAssignment[int, Valve], AStarMixin[Valve], ABC):
27 def parse_item(self, item: str) -> Valve:
28 match = valve_pattern.match(item)
29 name, flow_rate, tunnels_to = match.groups()
30
31 return Valve(
32 name=name,
33 tunnels_to=tunnels_to.split(", "),
34 flow_rate=int(flow_rate),
35 )
36
37 @staticmethod
38 def valve_map(input: Iterator[Valve]) -> Dict[str, Valve]:
39 return {valve.name: valve for valve in input}
40
41
42class AssignmentOne(Assignment):
43 example_result = 1651
44
45 def run(self, input: Iterator[Valve]) -> int:
46 valves = self.valve_map(input)
47
48 queue = [valves["AA"]]
49 open = {}
50 minutes = 30
51
52 while len(queue) > 0 or minutes > 0:
53 valve = queue.pop(0)
54
55 for v in valve.tunnels_to:
56 pass
57
58
59class AssignmentTwo(Assignment):
60 pass