aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-276/steven-wilson/python/ch-1.py26
-rw-r--r--challenge-276/steven-wilson/python/ch-2.py23
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-276/steven-wilson/python/ch-1.py b/challenge-276/steven-wilson/python/ch-1.py
new file mode 100644
index 0000000000..29fcb845e3
--- /dev/null
+++ b/challenge-276/steven-wilson/python/ch-1.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+from itertools import combinations
+
+
+def complete_day(*hours):
+ ''' Given an array of integers (hours),return the number of pairs that
+ forms a complete day.
+
+ A complete day is defined as a time duration that is an exact multiple
+ of 24 hours.
+
+ >>> complete_day(12, 12, 30, 24, 24)
+ 2
+ >>> complete_day(72, 48, 24, 5)
+ 3
+ >>> complete_day(12, 18, 24)
+ 0
+ '''
+ return sum(1 for pair in combinations(hours, 2) if sum(pair) % 24 == 0)
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod(verbose=True)
diff --git a/challenge-276/steven-wilson/python/ch-2.py b/challenge-276/steven-wilson/python/ch-2.py
new file mode 100644
index 0000000000..bf6a6edb55
--- /dev/null
+++ b/challenge-276/steven-wilson/python/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+from collections import Counter
+
+
+def maximum_frequency(*integers):
+ ''' Given an array of positive integers, return the total number of
+ elements in the given array which have the highest frequency.
+
+ >>> maximum_frequency(1, 2, 2, 4, 1, 5)
+ 4
+ >>> maximum_frequency(1, 2, 3, 4, 5)
+ 5
+ '''
+ counter = Counter(integers)
+ frequencies = list(zip(*counter.most_common()))[1]
+ return sum(f for f in frequencies if f == frequencies[0])
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod(verbose=True)