-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_reader.py
More file actions
48 lines (28 loc) · 793 Bytes
/
Copy pathinput_reader.py
File metadata and controls
48 lines (28 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import math
def read_input(file_path):
circles = []
radius = 0
with open(file_path) as file:
lines = file.readlines()
radius = int(lines[0])
for line in lines[1:]:
x, y = line.split()
x = int(x)
y = int(y)
circles.append([x, y])
return circles, radius
def calculate_distance(point1, point2):
x1, y1 = point1
x2, y2 = point2
distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return distance
def find_closest(circle, circles):
closest_distance = float('inf')
closest_circle = None
for other in circles:
if other != circle:
distance = calculate_distance(circle, other)
if distance < closest_distance:
closest_distance = distance
closest_circle = other
return closest_circle