diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-09-15 23:14:39 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-09-15 23:14:39 +0100 |
| commit | 9b49b3c00a595fbb7441615fea79b7fbc2694c99 (patch) | |
| tree | f75f7e7ff98d0103413a6adf03513ed65dd6777c /challenge-339/eric-cheung/python/ch-1.py | |
| parent | 7f78d729369f524a8bf4d7d9eb693aa689d78af6 (diff) | |
| download | perlweeklychallenge-club-9b49b3c00a595fbb7441615fea79b7fbc2694c99.tar.gz perlweeklychallenge-club-9b49b3c00a595fbb7441615fea79b7fbc2694c99.tar.bz2 perlweeklychallenge-club-9b49b3c00a595fbb7441615fea79b7fbc2694c99.zip | |
- 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.
Diffstat (limited to 'challenge-339/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-339/eric-cheung/python/ch-1.py | 17 |
1 files changed, 17 insertions, 0 deletions
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])
|
