-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxPointsOnLine.py
52 lines (35 loc) · 2.1 KB
/
MaxPointsOnLine.py
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
47
48
49
50
51
52
import numpy as np
list1 = [[-424,-512],[-4,-47],[0,-23],[-7,-65],[7,138],[0,27],[-5,-90],[-106,-146],[-420,-158],[-7,-128],[0,16],[-6,9],[-34,26],[-9,-166],[-570,-69],[-665,-85],[560,248],[1,-17],[630,277],[1,-7],[-287,-222],[30,250],[5,5],[-475,-53],[950,187],[7,-6],[-700,-274],[3,62],[-318,-390],[7,19],[-285,-21],[-5,4],[53,37],[-5,-1],[-2,-33],[-95,11],[4,1],[8,25],[700,306],[1,24],[-2,-6],[-35,-387],[-630,-245],[-328,-260],[-350,-129],[35,299],[-380,-37],[-9,-9],[210,103],[7,-5],[-3,-52],[-51,23],[-8,-147],[-371,-451],[-1,-14],[-41,6],[-246,-184],[350,161],[-212,-268],[-140,-42],[-9,-4],[-7,5],[10,6],[-15,-191],[-7,-4],[318,342],[-8,-71],[-68,20],[6,119],[6,13],[-280,-100],[140,74],[-760,-101],[0,-24],[-70,-13],[0,2],[0,-9],[106,98]]
if len(list1) == 1:
print(1)
else:
n = len(list1)
point_count = []
for i in range(0,n):
list2 = list1[i:n]
if len(list2) > 1:
for j in range(1,len(list2)):
dx = list2[0][0] - list2[j][0]
dy = list2[0][1] - list2[j][1]
counter = 0
if dx == 0:
x = list2[0][0]
for k in range(0,n):
if list1[k][0] == x:
counter += 1
elif dy == 0:
y = list2[0][1]
for k in range(0,n):
if list1[k][1] == y:
counter += 1
else:
m = dy/dx
def func(x):
y = m*(x-list2[0][0]) + list2[0][1]
return(y)
for k in range(0,n):
if list1[k][1] == round((func(list1[k][0])),5):
counter += 1
point_count.append(counter)
max_points = max(point_count)
print(max_points)