Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Break Rings by TovarischZhukov
# migrated from python 2.7
def find(data):
ff = {}
retval = []
for elem in data:
for val in elem:
ring = elem[0] if elem[1] == val else elem[1]
ff[val] = ff[val]+[ring] if val in ff else [ring]
m = len(min(list(ff.values()),key=len))
rings={(val,tuple(ff[val])) for elem in list(ff.values()) for val in elem if len(elem)==m}
ring=max(rings,key=lambda x: len(x[1]))[0]
new_data=[]
for elem in data:
if ring not in elem:
new_data.append(elem)
return find(new_data)+1 if new_data else 1
def break_rings(data):
new_data = []
for elem in data:
new_data.append(tuple(elem))
return find(new_data)
Jan. 7, 2016