Browse Source

Quick and dirty day 12.

master
Chris Smith 6 years ago
parent
commit
4132c197ab
2 changed files with 2022 additions and 0 deletions
  1. 22
    0
      12.py
  2. 2000
    0
      data/12.txt

+ 22
- 0
12.py View File

@@ -0,0 +1,22 @@
1
+with open('data/12.txt', 'r') as file:
2
+    pipes = list(map(lambda l: l.strip().replace(' <-> ', ', ').split(', '), file.readlines()))
3
+    groups = [set('0')]
4
+    while len(pipes):
5
+        for gi, group in enumerate(groups):
6
+            last_size = 0
7
+            while len(group) != last_size:
8
+                last_size = len(group)
9
+                remove = []
10
+                for pipeset in pipes:
11
+                    if any(program in group for program in pipeset):
12
+                        group = group.union(pipeset)
13
+                        groups[gi] = group
14
+                        remove.append(pipeset)
15
+                for pipeset in remove:
16
+                    pipes.remove(pipeset)
17
+        if len(pipes):
18
+            pipeset = pipes[0]
19
+            groups.append(set(pipeset))
20
+            pipes.remove(pipeset)
21
+    print(f'Part one: {len(groups[0])}')
22
+    print(f'Part two: {len(groups)}')

+ 2000
- 0
data/12.txt
File diff suppressed because it is too large
View File


Loading…
Cancel
Save