-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path102.py
More file actions
30 lines (26 loc) · 745 Bytes
/
102.py
File metadata and controls
30 lines (26 loc) · 745 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
#!/usr/bin/python
def contains0(a1,a2,b1,b2,c1,c2):
return intersect(a1,a2,b1,b2,c1,c2) and intersect(b1,b2,c1,c2,a1,a2) and intersect(c1,c2,a1,a2,b1,b2)
def intersect(a1, a2, b1, b2, c1, c2):
#calculate the point of intersection of A0 and BC
d=a1*(b2-c2)-a2*(b1-c1)
if d==0:
return False
else:
d+=.0
px=a1*(b1*c2-b2*c1)/d
py=a2*(b1*c2-b2*c1)/d
if ((px==0 and a1==0) or px/abs(px)==a1/abs(a1)) and ((py==0 and a2==0) or py/abs(py)==a2/abs(a2)):
if px==0 and a1==0 and py==0 and a2==0:
return False
else:
return True
else:
return False
tot=0
with open("102_triangles.txt") as f:
for line in f:
a1,a2,b1,b2,c1,c2 = [int(i) for i in line.split(",")]
if contains0(a1,a2,b1,b2,c1,c2):
tot+=1
print tot