aoc

commit 68b225181a115ff2898c6dc158dd35293f8d2e70

Author: Honza Pokorny <me@honza.ca>

Add d6p2

 006/main.py | 44 ++++++++++++++++++++++++++++++++++++++------


diff --git a/006/main.py b/006/main.py
index 96aef88c9cb279a6c552cfe4c83f846f40572cd7..256ed6a72847d35ef926893b4c6391141c5fc568 100644
--- a/006/main.py
+++ b/006/main.py
@@ -13,6 +13,20 @@ E)J
 J)K
 K)L"""
 
+data = """COM)B
+B)C
+C)D
+D)E
+E)F
+B)G
+G)H
+D)I
+E)J
+J)K
+K)L
+K)YOU
+I)SAN"""
+
 
 def add(a, b):
     return a + b
@@ -45,6 +59,12 @@
     return c
 
 
+def path(x, k):
+    if k == 'COM':
+        return []
+    return [x[k]] + path(x, x[k])
+
+
 def main():
     x = {}
 
@@ -56,15 +76,27 @@     assert_root(lines)
 
     for line in lines:
         a, b = line.split(')')
+        x[b] = a
 
-        if a not in x:
-            x[a] = [b]
+    you_path = path(x, 'YOU')
+    san_path = path(x, 'SAN')
+
+    you_path.reverse()
+    san_path.reverse()
+
+    common = []
+
+    for y, s in zip(you_path, san_path):
+        if y == s:
+            common.append(y)
         else:
-            xa = x[a]
-            xa.append(b)
-            x[a] = xa
+            break
+
+    print(you_path)
+    print(san_path)
+    print(common)
 
-    res = count(x, 'COM')
+    res = (len(you_path) - len(common)) + (len(san_path) - len(common))
     print(res)