Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Break Rings by samulih
# migrated from python 2.7
from functools import reduce
def break_rings(rings, count=0, u=set.union):
ids = reduce(u, rings, set())
if len(ids) < 2:
return count
conns = [reduce(u, (s - {i} for s in rings if i in s), set()) for i in ids]
n, smash = min((len(c), next(iter(c))) for c in conns)
return break_rings([r for r in rings if smash not in r], count + 1)
March 2, 2015
Comments: