Frans Bergman 3 years ago
parent
commit
e3fc999e83
5 changed files with 95 additions and 0 deletions
  1. 18 0
      12.huge.input
  2. 22 0
      12.input
  3. 38 0
      12.py
  4. 10 0
      12.small.input
  5. 7 0
      12.tiny.input

+ 18 - 0
12.huge.input

@@ -0,0 +1,18 @@
+fs-end
+he-DX
+fs-he
+start-DX
+pj-DX
+end-zg
+zg-sl
+zg-pj
+pj-he
+RW-he
+fs-DX
+pj-RW
+zg-RW
+start-pj
+he-WI
+zg-he
+pj-fs
+start-RW

+ 22 - 0
12.input

@@ -0,0 +1,22 @@
+xx-end
+EG-xx
+iy-FP
+iy-qc
+AB-end
+yi-KG
+KG-xx
+start-LS
+qe-FP
+qc-AB
+yi-start
+AB-iy
+FP-start
+iy-LS
+yi-LS
+xx-AB
+end-KG
+iy-KG
+qc-KG
+FP-xx
+LS-qc
+FP-yi

+ 38 - 0
12.py

@@ -0,0 +1,38 @@
+from util import get_input
+
+input = get_input("12.input")
+
+neighbour_map = {}
+
+def add_neighbour(a, b):
+    ns = neighbour_map.get(a, [])
+    ns.append(b)
+    neighbour_map[a] = ns
+
+for line in input:
+    [a, b] = line.split("-")
+    add_neighbour(a, b)
+    add_neighbour(b, a)
+
+def find_paths_1(current, prev):
+    if current == "end":
+        return 1
+    return sum([find_paths_1(next, prev + [current]) for next in neighbour_map[current] if not (next.islower() and next in prev)])
+
+print(find_paths_1("start", ["start"]))
+
+def ndup(ls):
+    curr = []
+    dups = 0
+    for l in ls:
+        if l in curr and l.islower():
+            dups += 1
+        curr.append(l)
+    return dups
+
+def find_paths_2(current, prev):
+    if current == "end":
+        return 1
+    return sum([find_paths_2(next, prev + [current]) for next in neighbour_map[current] if not ((next.islower() and next in prev and ndup(prev + [current]) > 0) or next == "start")])
+
+print(find_paths_2("start", []))

+ 10 - 0
12.small.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

+ 7 - 0
12.tiny.input

@@ -0,0 +1,7 @@
+start-A
+start-b
+A-c
+A-b
+b-d
+A-end
+b-end