From 9b49b3c00a595fbb7441615fea79b7fbc2694c99 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Mon, 15 Sep 2025 23:14:39 +0100 Subject: - Added solutions by Andreas Mahnke. - Added solutions by E. Choroba. - Added solutions by Eric Cheung. - Added solutions by W. Luis Mochan. - Added solutions by Peter Campbell Smith. - Added solutions by Peter Meszaros. - Added solutions by Thomas Kohler. --- challenge-339/eric-cheung/python/ch-1.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 challenge-339/eric-cheung/python/ch-1.py (limited to 'challenge-339/eric-cheung/python/ch-1.py') diff --git a/challenge-339/eric-cheung/python/ch-1.py b/challenge-339/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..9e84200c90 --- /dev/null +++ b/challenge-339/eric-cheung/python/ch-1.py @@ -0,0 +1,17 @@ + +from math import prod + +## Ref.: + +## arrInts = [5, 9, 3, 4, 6] ## Example 1 +## arrInts = [1, -2, 3, -4] ## Example 2 +## arrInts = [-3, -1, -2, -4] ## Example 3 +## arrInts = [10, 2, 0, 5, 1] ## Example 4 +arrInts = [7, 8, 9, 10, 10] ## Example 5 + +arrInts = sorted(arrInts) + +if all(nElem >= 0 for nElem in arrInts) or all(nElem <= 0 for nElem in arrInts): + print (abs(prod(arrInts[-2:]) - prod(arrInts[:2]))) +else: + print (arrInts[-3] * arrInts[-2] - arrInts[0] * arrInts[-1]) -- cgit