aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven1170@zoho.eu>2024-02-20 17:36:26 +0000
committerSteven <steven1170@zoho.eu>2024-02-20 17:36:26 +0000
commit1dc92eccd2fea8e8c533cc7a990baa9c2a38b8e8 (patch)
treefeef19fa172d329ebfabf33f34b18d850c0ef4c2
parentddd42e0db3017a5ec3108d09efba477f19e7f04b (diff)
downloadperlweeklychallenge-club-1dc92eccd2fea8e8c533cc7a990baa9c2a38b8e8.tar.gz
perlweeklychallenge-club-1dc92eccd2fea8e8c533cc7a990baa9c2a38b8e8.tar.bz2
perlweeklychallenge-club-1dc92eccd2fea8e8c533cc7a990baa9c2a38b8e8.zip
add solution week 257 task 1 in python
-rw-r--r--challenge-257/steven-wilson/python/ch-1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-257/steven-wilson/python/ch-1.py b/challenge-257/steven-wilson/python/ch-1.py
new file mode 100644
index 0000000000..9ceaaf849f
--- /dev/null
+++ b/challenge-257/steven-wilson/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+from collections import Counter
+
+
+def smaller_than_current(*integers):
+ ''' Given an array of integers, find out how many integers are smaller than
+ current i.e. foreach ints[i], count ints[j] < ints[i] where i != j
+ >>> smaller_than_current(5, 2, 1, 6)
+ (2, 1, 0, 3)
+ >>> smaller_than_current(1, 2, 0, 3)
+ (1, 2, 0, 3)
+ >>> smaller_than_current(0, 1)
+ (0, 1)
+ >>> smaller_than_current(9, 4, 9, 2)
+ (2, 1, 2, 0)
+ '''
+ integer_counter = Counter(integers)
+ results = []
+ for i in integers:
+ results.append(sum(count for key, count in integer_counter.items()
+ if key < i))
+ return tuple(results)
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()