aboutsummaryrefslogtreecommitdiff
path: root/challenge-123/abigail/python
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-07-28 18:13:24 +0200
committerAbigail <abigail@abigail.be>2021-07-28 18:13:24 +0200
commita42addb6a561d57e470cfed7828109bbfba040fb (patch)
treec18527120e6a1f8a71e04910bc03ccc7d1e5fffa /challenge-123/abigail/python
parentbd9797e1d52dc5b0853bc5400f04f477ffd6a4cb (diff)
downloadperlweeklychallenge-club-a42addb6a561d57e470cfed7828109bbfba040fb.tar.gz
perlweeklychallenge-club-a42addb6a561d57e470cfed7828109bbfba040fb.tar.bz2
perlweeklychallenge-club-a42addb6a561d57e470cfed7828109bbfba040fb.zip
Use methods to factor out calculations.
Diffstat (limited to 'challenge-123/abigail/python')
-rw-r--r--challenge-123/abigail/python/ch-2.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/challenge-123/abigail/python/ch-2.py b/challenge-123/abigail/python/ch-2.py
index e61a2cc0c5..437dc072ff 100644
--- a/challenge-123/abigail/python/ch-2.py
+++ b/challenge-123/abigail/python/ch-2.py
@@ -10,15 +10,15 @@
import fileinput
+def dist (x1, y1, x2, y2):
+ return (x1 - x2) ** 2 + (y1 - y2) ** 2
+
for line in fileinput . input ():
[x1, y1, x2, y2, x3, y3, x4, y4] = \
map (lambda x: int (x), line . split (' '))
- if (x1 - x2) ** 2 + (y1 - y2) ** 2 == \
- (x2 - x3) ** 2 + (y2 - y3) ** 2 == \
- (x3 - x4) ** 2 + (y3 - y4) ** 2 == \
- (x4 - x1) ** 2 + (y4 - y1) ** 2 and \
- (x1 - x3) ** 2 + (y1 - y3) ** 2 == \
- (x2 - x4) ** 2 + (y2 - y4) ** 2:
+ if dist (x1, y1, x2, y2) == dist (x2, y2, x3, y3) == \
+ dist (x3, y3, x4, y4) == dist (x4, y4, x1, y1) and \
+ dist (x1, y1, x3, y3) == dist (x2, y2, x4, y4):
print (1)
else:
print (0)