From 6861227d3965b4df842235d1a2f1358edbf6eed2 Mon Sep 17 00:00:00 2001 From: tomweber Date: Wed, 29 Dec 2021 14:37:15 +0100 Subject: [PATCH] started day12 --- day12_1.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ inputs/day12.input | 10 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 day12_1.py create mode 100644 inputs/day12.input diff --git a/day12_1.py b/day12_1.py new file mode 100644 index 0000000..a97a3de --- /dev/null +++ b/day12_1.py @@ -0,0 +1,45 @@ +import numpy as np +from collections import deque + +file = "inputs/day12.input" +lines = open(file, "rb").read().decode().split("\n")[:-1] +starts = [] +ends = [] +for line in lines: + start, end = line.split("-") + starts.append(start) + ends.append(end) + +nodes = set(starts + ends) +neighbours = {key: [] for key in nodes} + +for idx, start in enumerate(starts): + neighbours[start].append(ends[idx]) + neighbours[ends[idx]].append(start) + + +def find_way(node, way): + if node == "end": + way.append(node) + ways.append(way) + return + adjacents = neighbours[node] + if ( + len(adjacents) == 1 + and adjacents[0] == adjacents[0].lower() + and adjacents[0] in way + ): + return + way.append(node) + for adjacent in adjacents: + if adjacent == adjacent.lower() and adjacent in way: + continue + else: + find_way(adjacent, way.copy()) + + +ways = [] +find_way("start", []) +print(neighbours) +print(ways) +print(len(ways)) diff --git a/inputs/day12.input b/inputs/day12.input new file mode 100644 index 0000000..ef30b81 --- /dev/null +++ b/inputs/day12.input @@ -0,0 +1,10 @@ +dc-end +HN-start +start-kj +dc-start +dc-HN +LN-dc +HN-end +kj-sa +kj-HN +kj-dc \ No newline at end of file