aboutsummaryrefslogtreecommitdiff
path: root/challenge-152/lubos-kolouch/python
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-02-18 10:40:32 +0000
committerGitHub <noreply@github.com>2022-02-18 10:40:32 +0000
commit8952297006cc07b7393cf13a78d24fb1cb7ff99d (patch)
tree95858365980f672a9486a45c8766c393256ab55a /challenge-152/lubos-kolouch/python
parent3acd29f6195bfb005f78108c56423a018f2d44c4 (diff)
parentc4a63597ef2a392701b49be29f7615f0cad91cde (diff)
downloadperlweeklychallenge-club-8952297006cc07b7393cf13a78d24fb1cb7ff99d.tar.gz
perlweeklychallenge-club-8952297006cc07b7393cf13a78d24fb1cb7ff99d.tar.bz2
perlweeklychallenge-club-8952297006cc07b7393cf13a78d24fb1cb7ff99d.zip
Merge pull request #5668 from LubosKolouch/master
Challenge 152 LK Perl Python PHP Java
Diffstat (limited to 'challenge-152/lubos-kolouch/python')
-rw-r--r--challenge-152/lubos-kolouch/python/ch-1.py22
-rw-r--r--challenge-152/lubos-kolouch/python/ch-2.py43
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-152/lubos-kolouch/python/ch-1.py b/challenge-152/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..6e170349ca
--- /dev/null
+++ b/challenge-152/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,22 @@
+""" Challenge 152 Task 1 """
+
+
+def get_min_count(in_arr: list):
+ """ Find out the lists minimum """
+
+ min_sum = 0
+
+ for sub_arr in in_arr:
+
+ # so obviously it is not a tree, just independent arrays
+ # so I can just take a min from each row
+
+ min_sum += min(sub_arr)
+
+ return min_sum
+
+
+assert get_min_count([[1], [5, 3], [2, 3, 4], [7, 1, 0, 2], [6, 4, 5, 2,
+ 8]]) == 8
+assert get_min_count([[5], [2, 3], [4, 1, 5], [0, 1, 2, 3], [7, 2, 4, 1,
+ 9]]) == 9
diff --git a/challenge-152/lubos-kolouch/python/ch-2.py b/challenge-152/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..a7fe673bd6
--- /dev/null
+++ b/challenge-152/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,43 @@
+class Point:
+ def __init__(self, x: int, y: int):
+ self.x = x
+ self.y = y
+
+
+class Rectangle:
+ def __init__(self, left: Point, right: Point):
+ self.left = left
+ self.right = right
+
+ def get_area(self) -> int:
+ return abs(self.left.x - self.right.x) * abs(self.left.y -
+ self.right.y)
+
+
+def get_total_area(first: Rectangle, second: Rectangle) -> int:
+ area1 = first.get_area()
+ area2 = second.get_area()
+
+ # calculate the overlapping area
+ x_dist = min(first.right.x, second.right.x) - \
+ max(first.left.x, second.left.x)
+ y_dist = min(first.right.y, second.right.y) - \
+ max(first.left.y, second.left.y)
+ area_i = 0
+ if x_dist > 0 and y_dist > 0:
+ area_i = x_dist * y_dist
+
+ return area1 + area2 - area_i
+
+
+first = Rectangle(Point(-1, 0), Point(2, 2))
+second = Rectangle(Point(0, -1), Point(4, 4))
+
+if get_total_area(first, second) != 22:
+ raise Exception("Failed test 1")
+
+first = Rectangle(Point(-3, -1), Point(1, 3))
+second = Rectangle(Point(-1, -3), Point(2, 2))
+
+if get_total_area(first, second) != 25:
+ raise Exception("Failed test 2")