aboutsummaryrefslogtreecommitdiff
path: root/challenge-152/abigail/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-02-16 10:32:33 +0000
committerGitHub <noreply@github.com>2022-02-16 10:32:33 +0000
commit7c480291e4a71e4320fc98553de21c9eb47058c8 (patch)
tree88ec6352c250c5653550dec54fb15984523b022d /challenge-152/abigail/python/ch-2.py
parent348df89f110c0cc8654bc7ef97e1960e96c57ef2 (diff)
parentd6bba8467dbed369a17a8c8924d4cf51de6563b6 (diff)
downloadperlweeklychallenge-club-7c480291e4a71e4320fc98553de21c9eb47058c8.tar.gz
perlweeklychallenge-club-7c480291e4a71e4320fc98553de21c9eb47058c8.tar.bz2
perlweeklychallenge-club-7c480291e4a71e4320fc98553de21c9eb47058c8.zip
Merge pull request #5658 from Abigail/abigail/week-152
Week 152: Solutions in 8 languages.
Diffstat (limited to 'challenge-152/abigail/python/ch-2.py')
-rw-r--r--challenge-152/abigail/python/ch-2.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-152/abigail/python/ch-2.py b/challenge-152/abigail/python/ch-2.py
new file mode 100644
index 0000000000..08c884caad
--- /dev/null
+++ b/challenge-152/abigail/python/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/local/bin/python3
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-152
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+import fileinput
+
+for line in fileinput . input ():
+ [a_x1, a_y1, a_x2, a_y2, b_x1, b_y1, b_x2, b_y2] = \
+ [int (x) for x in line . split ()]
+ print ( (max (a_x1, a_x2) - min (a_x1, a_x2)) * \
+ (max (a_y1, a_y2) - min (a_y1, a_y2)) + \
+ (max (b_x1, b_x2) - min (b_x1, b_x2)) * \
+ (max (b_y1, b_y2) - min (b_y1, b_y2)) - \
+ max (0, min (max (a_x1, a_x2), max (b_x1, b_x2)) - \
+ max (min (a_x1, a_x2), min (b_x1, b_x2))) * \
+ max (0, min (max (a_y1, a_y2), max (b_y1, b_y2)) - \
+ max (min (a_y1, a_y2), min (b_y1, b_y2))))