Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Functional (?) solution in Creative category for Similar Triangles by suic
from itertools import combinations, starmap
from math import hypot
from operator import sub, truediv
from typing import List, Tuple
Coords = List[Tuple[int, int]]
def distance(p1: Coords, p2: Coords) -> float:
return hypot(*map(sub, *(p1, p2)))
def side_lengths(ps: Coords) -> List[float]:
return sorted(starmap(distance, combinations(ps, 2)))
def similar_triangles(coords_1: Coords, coords_2: Coords, precision: int=10) -> bool:
return len(set(round(s, precision) for s in map(truediv, *map(side_lengths, (coords_1, coords_2))))) == 1
March 28, 2020
Comments: