diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-02 12:42:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-02 12:42:42 +0100 |
| commit | 3f9ccc1651ed5ec64ca7724acb4c5011302b2ded (patch) | |
| tree | 79978af623e683e133ea5d14a87484f332dbeab2 | |
| parent | f8fdc04675bbed35a032652ee63f9af14d8275a4 (diff) | |
| parent | 72960a5959a03cb493e6c83a7ee32bc0a919c17d (diff) | |
| download | perlweeklychallenge-club-3f9ccc1651ed5ec64ca7724acb4c5011302b2ded.tar.gz perlweeklychallenge-club-3f9ccc1651ed5ec64ca7724acb4c5011302b2ded.tar.bz2 perlweeklychallenge-club-3f9ccc1651ed5ec64ca7724acb4c5011302b2ded.zip | |
Merge pull request #10351 from oWnOIzRi/week276
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..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) |
