def readfromfile(filename): with open(filename, 'r') as f: s = f.read() arr =…
- User
def read_from_file(filename): with open(filename, 'r') as f: s = f.read() arr = list(map(int, s.split())) return [[arr[i], arr[i+1]] for i in range(0, len(arr), 2)] points = read_from_file('input.txt') def jarvis(A): n = len(A) P = range(n) for i in range(1, n): if A[P[i]][0]<A[P[0]][0]: P[i], P[0] = P[0], P[i] H = [P[0]] del P[0] P.append(H[0]) while True: right = 0 for i in range(1, len(P)): if rotate(A[H[-1]],A[P[right]],A[P[i]])<0: right = i if P[right] == H[0]: break else: H.append(P[right]) del P[rigth] return [A[i] for i in H]
print(jarvis(points)) Исправь ошибку, особо не меняя код
- Assistant
The function
jarvisis attempting to implement the Jarvis March (also known as the Gift Wrapping algorithm) to compute the convex hull of a set of points. However, there are a couple of issues and a missing function definition that need to be addressed: