aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/steven-wilson/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-243/steven-wilson/python/ch-2.py')
-rw-r--r--challenge-243/steven-wilson/python/ch-2.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-243/steven-wilson/python/ch-2.py b/challenge-243/steven-wilson/python/ch-2.py
new file mode 100644
index 0000000000..4dc1b96750
--- /dev/null
+++ b/challenge-243/steven-wilson/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+from itertools import product
+from math import floor
+
+
+def floor_sum(*elements):
+ '''
+ return the sum of floor(nums[i] / nums[j]) where 0 <= i,j < nums.length
+ >>> floor_sum(2, 5, 9)
+ 10
+ >>> floor_sum(7, 7, 7, 7, 7, 7, 7)
+ 49
+ '''
+ sum = 0
+ prod = product(range(len(elements)), repeat=2)
+ for i, j in prod:
+ if 0 <= i and j < len(elements):
+ sum += floor(elements[i] / elements[j])
+ return sum
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()