-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissquare.py2
43 lines (41 loc) · 1.05 KB
/
issquare.py2
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
#!/usr/bin/python
from sys import argv
try:
FILE = argv[1]
except NameError:
FILE = 'tests/101'
DATA = open(FILE, 'r').read().splitlines()
from math import sqrt
points=[]
# get distance between two tuples a b with two coords each
def dist(a,b):
return sqrt( pow(abs(b[0]-a[0]),2) + pow(abs(b[1]-a[1]),2) )
for line in DATA:
if not line:
continue
points = eval(line)
p0,p1,p2,p3 = points
if p0==p1==p2==p3:
square = False
elif dist(p0,p1) == dist(p0,p2):
if dist(p1,p2) == dist(p0,p3):
square = True
else: square = False
elif dist(p0,p1) == dist(p0,p3):
if dist(p0,p2) == dist(p1,p3):
square = True
else: square = False
elif dist(p0,p2) == dist(p0,p3):
if dist(p0,p1) == dist(p2,p3):
square = True
else: square = False
else: square = False
print str(square).lower()
# dists=[]
# for p in points:
# dists.append(dist(points[0],p))
# d1,d2,d3 = dists
# square = False
# if d1 == d2:
# if d3 == dist
#