forked from cdubz/advent-of-code-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digital_plumber_part_two.py
31 lines (25 loc) · 983 Bytes
/
digital_plumber_part_two.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
--- Part Two ---
There are more programs than just the ones in the group containing program ID 0.
The rest of them have no way of reaching that group, and still might have no way
of reaching each other.
A group is a collection of programs that can all communicate via pipes either
directly or indirectly. The programs you identified just a moment ago are all
part of the same group. Now, they would like you to determine the total number
of groups.
In the example above, there were 2 groups: one consisting of programs
0,2,3,4,5,6, and the other consisting solely of program 1.
How many groups are there in total?
"""
from utils.plumb import plumb
pipes = {}
with open('input.txt') as f:
for line in f:
data = line.split(' <-> ')
pipes[int(data[0])] = [int(v) for v in data[1].strip().split(', ')]
groups = []
for parent in pipes:
group = set(plumb(pipes, parent, [], []))
if group not in groups:
groups.append(group)
print(len(groups))