Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
[Generalized] All equal distance² fractions solution in Clear category for Similar Triangles by Phil15
from itertools import combinations
from fractions import Fraction
def all_equal(iterator) -> bool:
first = next(iterator)
return all(elem == first for elem in iterator)
def sorted_dists(triangle): # [A, B, C] --> [AB², AC², BC²] sorted
return sorted((xB - xA) ** 2 + (yB - yA) ** 2
for (xA, yA), (xB, yB) in combinations(triangle, 2))
def similar_triangles(*triangles) -> bool:
distances = map(sorted_dists, triangles)
first = next(distances)
return all(all_equal(map(Fraction, first, dists)) for dists in distances)
Jan. 26, 2020
Comments: