aboutsummaryrefslogtreecommitdiff
path: root/challenge-251/lubos-kolouch/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-251/lubos-kolouch/python')
-rw-r--r--challenge-251/lubos-kolouch/python/ch-1.py23
-rw-r--r--challenge-251/lubos-kolouch/python/ch-2.py32
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-251/lubos-kolouch/python/ch-1.py b/challenge-251/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..62a2fcd678
--- /dev/null
+++ b/challenge-251/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,23 @@
+from typing import List
+
+
+def concatenation_value(ints: list[int]) -> int:
+ concat_value = 0
+ while len(ints) > 0:
+ if len(ints) == 1:
+ concat_value += ints[0]
+ del ints[0]
+ else:
+ first = str(ints[0])
+ last = str(ints[-1])
+ concat = int(first + last)
+ concat_value += concat
+ del ints[0]
+ del ints[-1]
+ return concat_value
+
+
+# Tests
+assert concatenation_value([6, 12, 25, 1]) == 1286
+assert concatenation_value([10, 7, 31, 5, 2, 2]) == 489
+assert concatenation_value([1, 2, 10]) == 112
diff --git a/challenge-251/lubos-kolouch/python/ch-2.py b/challenge-251/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..8983f5e6f0
--- /dev/null
+++ b/challenge-251/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,32 @@
+from typing import List
+
+
+def lucky_number(matrix: list[list[int]]) -> int:
+ """
+ Returns the lucky number in the given matrix, if there is one, or -1 if not.
+
+ A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.
+
+ Args:
+ matrix: A list of lists of integers representing the matrix.
+
+ Returns:
+ An integer representing the lucky number, or -1 if there is no lucky number in the matrix.
+ """
+ for i in range(len(matrix)):
+ min_row = min(matrix[i])
+ min_index = matrix[i].index(min_row)
+ if all(matrix[j][min_index] <= min_row for j in range(len(matrix))):
+ return min_row
+ return -1
+
+
+# Example usage
+matrix1 = [[3, 7, 8], [9, 11, 13], [15, 16, 17]]
+print(lucky_number(matrix1)) # Output: 15
+
+matrix2 = [[1, 10, 4, 2], [9, 3, 8, 7], [15, 16, 17, 12]]
+print(lucky_number(matrix2)) # Output: 12
+
+matrix3 = [[7, 8], [1, 2]]
+print(lucky_number(matrix3)) # Output: 7