You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1001 B

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))