diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-11-27 03:54:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-27 03:54:38 +0000 |
| commit | cb022b4b355f1472d4a3f7d5ca2c0ba483a5fb47 (patch) | |
| tree | 3896fca3cb1c7958821980005626f414bc45a708 /challenge-244/sgreen/python | |
| parent | efa61047dd4b74d53c415252ee3ba9fb02fe144e (diff) | |
| parent | 59481daad96eaa27bd9c4ecd81010941285c496e (diff) | |
| download | perlweeklychallenge-club-cb022b4b355f1472d4a3f7d5ca2c0ba483a5fb47.tar.gz perlweeklychallenge-club-cb022b4b355f1472d4a3f7d5ca2c0ba483a5fb47.tar.bz2 perlweeklychallenge-club-cb022b4b355f1472d4a3f7d5ca2c0ba483a5fb47.zip | |
Merge pull request #9136 from simongreen-net/master
Simon's solution to challenge 244
Diffstat (limited to 'challenge-244/sgreen/python')
| -rwxr-xr-x | challenge-244/sgreen/python/ch-1.py | 14 | ||||
| -rwxr-xr-x | challenge-244/sgreen/python/ch-2.py | 25 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-244/sgreen/python/ch-1.py b/challenge-244/sgreen/python/ch-1.py new file mode 100755 index 0000000000..230798c214 --- /dev/null +++ b/challenge-244/sgreen/python/ch-1.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import sys + + +def main(ints): + solution = [sum(1 for j in ints if j < i) for i in ints] + print(*solution, sep=', ') + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) diff --git a/challenge-244/sgreen/python/ch-2.py b/challenge-244/sgreen/python/ch-2.py new file mode 100755 index 0000000000..64f54aff7a --- /dev/null +++ b/challenge-244/sgreen/python/ch-2.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +from itertools import combinations + + +def calculate_power(numbers): + '''Return the square of the maximum number multiplied by the smallest one''' + min_int = min(numbers) + max_int = max(numbers) + return max_int ** 2 * min_int + + +def main(ints): + power = 0 + for length in range(1, len(ints)+1): + power += sum(calculate_power(c) for c in combinations(ints, length)) + + print(power) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) |
