Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7-liner, recursion + frozenset solution in Clear category for Count Chains by kdim
from typing import List, Tuple
def count_chains(circles: List[Tuple[int, int, int]]) -> int:
def intersect(x1, y1, r1, x2, y2, r2):
return abs(r1 - r2) < ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 < r1 + r2
def chain(ch):
res = ch | {circle for circle in circles if any(intersect(*circle, *c) for c in ch)}
return res if ch == res else chain(res)
return len({frozenset(chain({circle})) for circle in circles})
Feb. 19, 2021
Comments: