From 59481daad96eaa27bd9c4ecd81010941285c496e Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 26 Nov 2023 22:22:13 +1100 Subject: Simon's solution to challenge 244 --- challenge-244/sgreen/python/ch-2.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 challenge-244/sgreen/python/ch-2.py (limited to 'challenge-244/sgreen/python/ch-2.py') 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) -- cgit