Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use sets to join ajusted sides and eliminate collinear ones solution in Creative category for Number of Sides by frbrgeorge
from itertools import pairwise, combinations
from collections import Counter
Coordinate = tuple[int, int]
Triangle = tuple[Coordinate, Coordinate, Coordinate]
def number_of_sides(triangles: list[Triangle, ...]) -> int:
sides = {key for key, val in Counter(tuple(sorted(s)) for t in triangles for s in pairwise(t + (t[0],))).items() if val == 1}
while True:
for s1, s2 in combinations(sides, 2):
if s1[0] == s2[1] or s1[1] == s2[0]:
(x1, y1), (x2, y2), (x3, y3) = tuple(sorted({*(s1 + s2)}))
if (y3 - y2) * (x2 - x1) == (y2 - y1) * (x3 - x2):
sides -= {s1, s2}
if ((x1, y1), (x3, y3)) in sides:
sides -= {((x1, y1), (x3, y3))}
else:
sides.add(((x1, y1), (x3, y3)))
break
else:
break
return len(sides)
Sept. 14, 2024
Comments: