From 779efe068942ffc6907d58d2008457b23cbc4415 Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 11 Feb 2023 15:02:18 -0500 Subject: [PATCH] solved 12a --- 2021/day12/12.py | 31 +++++++++++++++++++++++++++++++ 2021/day12/input.txt.sample | 7 +++++++ 2 files changed, 38 insertions(+) create mode 100644 2021/day12/12.py create mode 100644 2021/day12/input.txt.sample diff --git a/2021/day12/12.py b/2021/day12/12.py new file mode 100644 index 0000000..5149bfe --- /dev/null +++ b/2021/day12/12.py @@ -0,0 +1,31 @@ +lines = [ i.split('-') for i in open("input.txt", 'r').read().splitlines()] + +paths = [] + +di = {} +for l in lines: + if l[0] not in di: + di[l[0]] = [] + di[l[0]].append(l[1]) + if l[1] not in di: + di[l[1]] = [] + di[l[1]].append(l[0]) + +print(di) + +def travel(stack, node): + stack.append(node) + if node == 'end': + paths.append(stack.copy()) + print(stack) + for n in di[node]: + if n not in stack or n.isupper(): + travel(stack,n) + stack.pop() + +for start in di['start']: + stack = ['start'] + travel(stack, start) + + +print(len(paths)) \ No newline at end of file diff --git a/2021/day12/input.txt.sample b/2021/day12/input.txt.sample new file mode 100644 index 0000000..898cd56 --- /dev/null +++ b/2021/day12/input.txt.sample @@ -0,0 +1,7 @@ +start-A +start-b +A-c +A-b +b-d +A-end +b-end \ No newline at end of file