#!/usr/bin/env python3 import collections import sys input_file = sys.argv[1] with open(input_file) as fd: lines = [line.rstrip() for line in fd.readlines()] connections = [set(line.split("-")) for line in lines] codi: collections.defaultdict[str, set[str]] = collections.defaultdict(set) for connection in connections: a, b = connection codi[a].add(b) codi[b].add(a) threes: set[tuple[str, ...]] = set() for connection in connections: a, b = connection ac, bc = codi[a], codi[b] iis = ac.intersection(bc) for i in iis: threel = [a, b, i] threel.sort() threes.add(tuple(threel)) j = 0 while len(threes) > 1: inthrees: set[str] = set() for three in threes: inthrees.update(set(three)) print(j, len(threes), len(inthrees)) fours: set[tuple[str, ...]] = set() for three in threes: threeset = set(three) for comp in inthrees - threeset: compc = codi[comp] if threeset.issubset(compc): fourl = list(threeset) + [comp] fourl.sort() fours.add(tuple(fourl)) threes = fours threesl = list(threes) if len(threesl) == 1: three = threesl[0] print(",".join(three)) print(None)