Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Similar Triangles by ches993
from typing import List, Tuple
import math
Coords = List[Tuple[int, int]]
def similar_triangles(coords_1: Coords, coords_2: Coords) -> bool:
coords_3=[(coords_1[0][0]-coords_1[1][0],coords_1[0][1]-coords_1[1][1]),(coords_1[1][0]-coords_1[2][0],coords_1[1][1]-coords_1[2][1]),(coords_1[0][0]-coords_1[2][0],coords_1[0][1]-coords_1[2][1])]
coords_4=[(coords_2[0][0]-coords_2[1][0],coords_2[0][1]-coords_2[1][1]),(coords_2[1][0]-coords_2[2][0],coords_2[1][1]-coords_2[2][1]),(coords_2[0][0]-coords_2[2][0],coords_2[0][1]-coords_2[2][1])]
a1 = abs (math.sqrt(coords_3[0][0] ** 2 + coords_3[0][1] ** 2))
b1 = abs (math.sqrt(coords_3[1][0] ** 2 + coords_3[1][1] ** 2))
c1 = abs (math.sqrt(coords_3[2][0] ** 2 + coords_3[2][1] ** 2))
a2 = abs(math.sqrt(coords_4[0][0] ** 2 + coords_4[0][1] ** 2))
b2 = abs(math.sqrt(coords_4[1][0] ** 2 + coords_4[1][1] ** 2))
c2 = abs(math.sqrt(coords_4[2][0] ** 2 + coords_4[2][1] ** 2))
array_1 = sorted([a1,b1,c1],reverse=True)
array_2 = sorted([a2,b2,c2],reverse=True)
similar = round(array_1[0]/array_2[0],2) == round(array_1[1]/array_2[1],2) == round(array_1[2] /array_2[2],2)
return similar
# вжух и все работает
if __name__ == '__main__':
print("Example:")
print(similar_triangles([(0, 0), (1, 2), (2, 0)], [(3, 0), (4, 2), (5, 0)]))
# These "asserts" are used for self-checking and not for an auto-testing
assert similar_triangles([(0, 0), (1, 2), (2, 0)], [(3, 0), (4, 2), (5, 0)]) is True, 'basic'
assert similar_triangles([(0, 0), (1, 2), (2, 0)], [(3, 0), (4, 3), (5, 0)]) is False, 'different #1'
assert similar_triangles([(0, 0), (1, 2), (2, 0)], [(2, 0), (4, 4), (6, 0)]) is True, 'scaling'
assert similar_triangles([(0, 0), (0, 3), (2, 0)], [(3, 0), (5, 3), (5, 0)]) is True, 'reflection'
assert similar_triangles([(1, 0), (1, 2), (2, 0)], [(3, 0), (5, 4), (5, 0)]) is True, 'scaling and reflection'
assert similar_triangles([(1, 0), (1, 3), (2, 0)], [(3, 0), (5, 5), (5, 0)]) is False, 'different #2'
print("Coding complete? Click 'Check' to earn cool rewards!")
April 19, 2021
Comments: