From 2d1263453d26cd2c6a64a3b6141ee0a12ddc0b11 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sat, 17 Dec 2022 16:35:17 +0100 Subject: Day 16 [WIP] --- day16/__init__.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 day16/__init__.py (limited to 'day16/__init__.py') 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 @@ +# -*- 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 -- cgit v1.2.3