aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/lubos-kolouch/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-243/lubos-kolouch/python/ch-2.py')
-rw-r--r--challenge-243/lubos-kolouch/python/ch-2.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-243/lubos-kolouch/python/ch-2.py b/challenge-243/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..eea7bf2a01
--- /dev/null
+++ b/challenge-243/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+import math
+from typing import List
+
+
+def floor_sum(nums: list[int]) -> int:
+ """
+ Calculate the sum of floor division results for every combination of elements in the array.
+
+ Args:
+ nums (List[int]): A list of positive integers.
+
+ Returns:
+ int: The sum of the floor division results.
+ """
+ return sum(
+ math.floor(nums[i] / nums[j])
+ for i in range(len(nums))
+ for j in range(len(nums))
+ )
+
+
+# Tests
+assert floor_sum([2, 5, 9]) == 10
+assert floor_sum([7, 7, 7, 7, 7, 7, 7]) == 49