aboutsummaryrefslogtreecommitdiff
path: root/challenge-187/sgreen/python/ch-2.py
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2022-10-24 17:44:04 +0800
committer冯昶 <fengchang@novel-supertv.com>2022-10-24 17:44:04 +0800
commit7783ecb7dad2ae5ea3d3022a13e3901c196c4154 (patch)
treefa408d0b19c541602d81799c8a13eea61df2cb8f /challenge-187/sgreen/python/ch-2.py
parenta406c6935f88c7afa04a707a2611ebe4fe4eadae (diff)
parentbb06570f6b1634ca14bfd08927f3bfc6c052c494 (diff)
downloadperlweeklychallenge-club-7783ecb7dad2ae5ea3d3022a13e3901c196c4154.tar.gz
perlweeklychallenge-club-7783ecb7dad2ae5ea3d3022a13e3901c196c4154.tar.bz2
perlweeklychallenge-club-7783ecb7dad2ae5ea3d3022a13e3901c196c4154.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-187/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-187/sgreen/python/ch-2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-187/sgreen/python/ch-2.py b/challenge-187/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..e76921c374
--- /dev/null
+++ b/challenge-187/sgreen/python/ch-2.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+import sys
+from decimal import Decimal
+from itertools import combinations
+
+
+def main(array):
+ solution = None
+
+ # Turn the array into integers
+ n = [Decimal(x) for x in array]
+
+ # Calculate for all combinations
+ for new in combinations(n, 3):
+ (a, b, c) = new
+ if a + b > c and b + c > a and a + c > b:
+ if solution is None or sum(new) > sum(solution):
+ solution = sorted(new, reverse = True)
+
+ if solution:
+ print('(' + ', '.join(str(x) for x in solution) + ')')
+ else:
+ print('()')
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])