Solución
solution.tsTypeScript
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def magnitude_sq(self):
return self.x ** 2 + self.y ** 2
def __eq__(self, other) -> bool:
# Retorna True si ambos vectores tienen la misma magnitud
return (self.magnitude_sq() == other.magnitude_sq())
def __lt__(self, other) -> bool:
# Retorna True si este vector tiene menor magnitud que el otro
return (self.magnitude_sq() < other.magnitude_sq())
def compare_vectors(v1, v2):
a = Vector(v1[0], v1[1])
b = Vector(v2[0], v2[1])
return {"equal": a == b, "v1_less": a < b}
0respuestas