Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
14-liner: easy complex solution in Clear category for Inscribe a Contour by przemyslaw.daniel
from typing import List, Tuple
from itertools import combinations
from cmath import phase, exp, inf
def inscribe(contour: List[Tuple[float, float]]) -> int:
contour, result = [x + 1j * y for x, y in contour], inf
for a, b in combinations(contour, 2):
phase_angle = -1j * phase(1j * (b - a))
rotated = [pt * exp(phase_angle) for pt in contour]
xs, ys = zip(*[(pt.real, pt.imag) for pt in rotated])
width, height = max(xs) - min(xs), max(ys) - min(ys)
result = min(result, width * height)
return result
Jan. 10, 2021