Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clean and check solution in Clear category for Number of Sides by amandel
Coordinate = tuple[int, int]
Triangle = tuple[Coordinate, Coordinate, Coordinate]
from itertools import combinations
def number_of_sides(triangles: list[Triangle, ...]) -> int:
sides = [{i + j, i + k, j + k} for i, j, k in map(sorted, triangles)]
fin = set()
for s in sides:
fin.symmetric_difference_update(s)
n = len(fin)
for x, y in combinations(sorted(fin), 2):
a, b, c, d, e, f, g, h = x + y
n -= (c, d, (h - f) * (c - a)) == (e, f, (g - e) * (d - b))
return n
print("Example:")
print(number_of_sides([((1, 3), (3, 3), (1, 1)), ((3, 3), (3, 1), (1, 1))]))
# These "asserts" are used for self-checking
assert number_of_sides([((1, 3), (3, 3), (1, 1)), ((3, 3), (3, 1), (1, 1))]) == 4
assert number_of_sides([((1, 1), (2, 3), (2, 1)), ((2, 3), (3, 1), (2, 1))]) == 3
assert (
number_of_sides(
[
((1, 3), (3, 3), (2, 2)),
((3, 3), (3, 1), (2, 2)),
((3, 1), (1, 1), (2, 2)),
((1, 1), (1, 3), (2, 2)),
]
)
== 4
)
assert (
number_of_sides(
[
((3, 5), (4, 3), (2, 3)),
((4, 3), (5, 1), (3, 1)),
((3, 1), (1, 1), (2, 3)),
((2, 3), (4, 3), (3, 1)),
]
)
== 3
)
assert (
number_of_sides(
[
((6, 10), (11, 7), (1, 7)),
((11, 7), (9, 1), (1, 7)),
((9, 1), (3, 1), (1, 7)),
]
)
== 5
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 15, 2024