-
Notifications
You must be signed in to change notification settings - Fork 1
/
12b_aoc.py
40 lines (35 loc) · 858 Bytes
/
12b_aoc.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
32
33
34
35
36
37
38
39
40
programs = {}
def main():
try:
while True:
process(raw_input())
except EOFError:
collect_sets()
analyse_results()
def process(inp):
inp = inp.replace(","," ").split()
programs[inp[0]] = set(inp[2:])
def collect_sets():
for key in programs:
value = programs[key]
for prog in value:
set_a = programs[key]
set_b = programs[prog]
set_u = set_a.union(set_b)
programs[key] = set_u
programs[prog] = set_u
def analyse_results():
import time
numgrps = 0
#while True:
keys = programs.keys()
for key in keys:
try:
s = programs[key]
for p in s:
if p!=key:
programs.pop(p)
except KeyError:
pass
print len(programs)
main()