diff options
| author | Steven <steven1170@zoho.eu> | 2024-07-01 12:22:05 +0100 |
|---|---|---|
| committer | Steven <steven1170@zoho.eu> | 2024-07-01 12:22:05 +0100 |
| commit | 4f69a51e87ac0e32786d81e99457db6bd5fac53b (patch) | |
| tree | bed700dce0d0043524c0579cadd773a507837f43 | |
| parent | f18cb7a95e46b9ded70a2d1d932d0bb7b1772a67 (diff) | |
| download | perlweeklychallenge-club-4f69a51e87ac0e32786d81e99457db6bd5fac53b.tar.gz perlweeklychallenge-club-4f69a51e87ac0e32786d81e99457db6bd5fac53b.tar.bz2 perlweeklychallenge-club-4f69a51e87ac0e32786d81e99457db6bd5fac53b.zip | |
add solutions week 276 in python
| -rw-r--r-- | challenge-276/steven-wilson/python/ch-1.py | 26 | ||||
| -rw-r--r-- | challenge-276/steven-wilson/python/ch-2.py | 23 |
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..7735ae8328 --- /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) + frequency = list(zip(*counter.most_common()))[1] + return sum(value for value in frequency if value == frequency[0]) + + +if __name__ == "__main__": + import doctest + + doctest.testmod(verbose=True) |
