Question: Ocaml: fix the code to realize distance: (int * int) -> (int * int) -> float: Given two points (x1, y1) and (x2, y2), return
distance: (int * int) -> (int * int) -> float: Given two points (x1, y1) and (x2, y2), return the Euclidean distance between the two points, equivalent to the length of a straight line segment connecting the two points. The result should be returned as a floating-point number. let distance_tests = [ (((0, 0), (3, 4)), (5.) ); ( ((@, 0), (1, 1)), (1.4) ); |] let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = (x1 - x2) in let dy = (y1 y2) in return sqrt (dx * dx + dy * dy)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
