diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-03-06 18:41:45 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-03-06 18:41:45 +0800 |
| commit | 849fbc07ea10ad83d018bccc357c758e8855474e (patch) | |
| tree | f3a77db28df57c8507010d1983f8dfe16eb07737 /challenge-206/eric-cheung/python/ch-2.py | |
| parent | d2cca4f3533f095d018affa34893ac385b6b02af (diff) | |
| parent | d75c83429332efc88f29eee14f988b199f2fa10c (diff) | |
| download | perlweeklychallenge-club-849fbc07ea10ad83d018bccc357c758e8855474e.tar.gz perlweeklychallenge-club-849fbc07ea10ad83d018bccc357c758e8855474e.tar.bz2 perlweeklychallenge-club-849fbc07ea10ad83d018bccc357c758e8855474e.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-206/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-206/eric-cheung/python/ch-2.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-206/eric-cheung/python/ch-2.py b/challenge-206/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..3b9ae04009 --- /dev/null +++ b/challenge-206/eric-cheung/python/ch-2.py @@ -0,0 +1,41 @@ +
+from itertools import combinations
+
+def GetSetFromArrInput(arrFuncInput):
+
+ arrOutputArr = []
+
+ arrCombList = combinations(arrFuncInput, 2)
+
+ for loopComb in list(arrCombList):
+ arrOutputArr.append([loopComb[0], loopComb[1]])
+
+ return arrOutputArr
+
+
+## arrInput = [1, 2, 3, 4] ## Example 1
+arrInput = [0, 2, 1, 3] ## Example 2
+
+arrCombSubList = combinations(range(0, len(arrInput)), 2)
+
+arrSumOutput = []
+
+for loopSubComb in list(arrCombSubList):
+
+ arrSubInput = arrInput[:]
+
+ arrSubList_01 = [arrSubInput[loopSubComb[0]], arrSubInput[loopSubComb[1]]]
+
+ arrSubInput.pop(loopSubComb[1])
+ arrSubInput.pop(loopSubComb[0])
+
+ arrSubList_02 = GetSetFromArrInput(arrSubInput)
+
+ for nLoop in range(0, len(arrSubList_02)):
+
+ if arrSubList_01[0] > arrSubList_02[nLoop][0]:
+ continue
+
+ arrSumOutput.append(min(arrSubList_01) + min(arrSubList_02[nLoop]))
+
+print (max(arrSumOutput))
|
