aboutsummaryrefslogtreecommitdiff
path: root/challenge-218/robert-dicicco/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-23 19:56:21 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-23 19:56:21 +0100
commitf88ec70a8f56f1d4e7ecf28b0062d46b82f8b030 (patch)
treee97b3042d70c219ae232b875b629faab892b4244 /challenge-218/robert-dicicco/python
parenta0378812481339d92fae9464fbd9e98bcca04ff5 (diff)
downloadperlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.tar.gz
perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.tar.bz2
perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.zip
- Added solutions by Mark Anderson.
- Added solutions by Stephen G. Lynn. - Added solutions by David Ferrone. - Added solutions by Thomas Kohler. - Added solutions by Niels van Dijke. - Added solutions by W. Luis Mochan. - Added solutions by Steven Wilson. - Added solutions by Robert DiCicco. - Added solutions by Lubos Kolouch.
Diffstat (limited to 'challenge-218/robert-dicicco/python')
-rw-r--r--challenge-218/robert-dicicco/python/ch-1.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-218/robert-dicicco/python/ch-1.py b/challenge-218/robert-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..0cb5363087
--- /dev/null
+++ b/challenge-218/robert-dicicco/python/ch-1.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+# -----------------------------------------
+# AUTHOR: Robert DiCicco
+# DATE : 2023-05-22
+# Challenge 218 Maximum Product ( Python )
+# -----------------------------------------
+
+from itertools import combinations
+
+
+lists = [[3, 1, 2],[4, 1, 3, 2],[-1, 0, 1, 3, 1],[-8, 2, -9, 0, -4, 3]]
+
+maxthree = []
+
+for lst in lists:
+ print("Input: @list = ",lst)
+ maxval = 0
+ maxthree = []
+ for combo in list(combinations(lst,3)):
+ prod = combo[0] * combo[1] * combo[2]
+ if prod > maxval:
+ maxval = prod
+ maxthree = combo
+ print("Output: ",maxval)
+ maxthree = sorted(maxthree)
+ print(maxthree[0]," x ", maxthree[1], " x ", maxthree[2], " = ",maxval,"\n")
+ maxval = 0
+
+# -----------------------------------------
+# SAMPLE OUTPUT
+# python .\MaxProduct.py
+
+# Input: @list = [3, 1, 2]
+# Output: 6
+# 1 x 2 x 3 = 6
+
+# Input: @list = [4, 1, 3, 2]
+# Output: 24
+# 2 x 3 x 4 = 24
+
+# Input: @list = [-1, 0, 1, 3, 1]
+# Output: 3
+# 1 x 1 x 3 = 3
+
+# Input: @list = [-8, 2, -9, 0, -4, 3]
+# Output: 216
+# -9 x -8 x 3 = 216
+# -----------------------------------------
+
+