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
54
55
56
57
58
59
60
|
# -*- coding: utf-8 -*-
import re
from abc import ABC
from dataclasses import dataclass
from typing import List, Iterator, Dict
from aoc import BaseAssignment
from aoc.mixins import AStarMixin
@dataclass
class Valve:
name: str
flow_rate: int
tunnels_to: List[str]
def __hash__(self):
return hash(self.name)
valve_pattern = re.compile(
"Valve (\w+) has flow rate=(\d+); tunnels? leads? to valves? (.*)"
)
class Assignment(BaseAssignment[int, Valve], AStarMixin[Valve], ABC):
def parse_item(self, item: str) -> Valve:
match = valve_pattern.match(item)
name, flow_rate, tunnels_to = match.groups()
return Valve(
name=name,
tunnels_to=tunnels_to.split(", "),
flow_rate=int(flow_rate),
)
@staticmethod
def valve_map(input: Iterator[Valve]) -> Dict[str, Valve]:
return {valve.name: valve for valve in input}
class AssignmentOne(Assignment):
example_result = 1651
def run(self, input: Iterator[Valve]) -> int:
valves = self.valve_map(input)
queue = [valves["AA"]]
open = {}
minutes = 30
while len(queue) > 0 or minutes > 0:
valve = queue.pop(0)
for v in valve.tunnels_to:
pass
class AssignmentTwo(Assignment):
pass
|