aboutsummaryrefslogtreecommitdiff
path: root/challenge-206/eric-cheung/python
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-03-06 18:41:45 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-03-06 18:41:45 +0800
commit849fbc07ea10ad83d018bccc357c758e8855474e (patch)
treef3a77db28df57c8507010d1983f8dfe16eb07737 /challenge-206/eric-cheung/python
parentd2cca4f3533f095d018affa34893ac385b6b02af (diff)
parentd75c83429332efc88f29eee14f988b199f2fa10c (diff)
downloadperlweeklychallenge-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')
-rwxr-xr-xchallenge-206/eric-cheung/python/ch-1.py24
-rwxr-xr-xchallenge-206/eric-cheung/python/ch-2.py41
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-206/eric-cheung/python/ch-1.py b/challenge-206/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..4968d9ef1a
--- /dev/null
+++ b/challenge-206/eric-cheung/python/ch-1.py
@@ -0,0 +1,24 @@
+
+from datetime import datetime
+
+## arrTimeInput = ["00:00", "23:55", "20:00"] ## Example 1
+## arrTimeInput = ["01:01", "00:50", "00:57"] ## Example 2
+arrTimeInput = ["10:10", "09:30", "09:00", "09:55"] ## Example 3
+
+arrTimeMinDiff = []
+
+for nIndxLoop_01 in range(0, len(arrTimeInput) - 1):
+ for nIndxLoop_02 in range(nIndxLoop_01 + 1, len(arrTimeInput)):
+
+ tLoop_01 = datetime.strptime(arrTimeInput[nIndxLoop_01], "%H:%M")
+ tLoop_02 = datetime.strptime(arrTimeInput[nIndxLoop_02], "%H:%M")
+
+ if tLoop_01 <= tLoop_02:
+ tDiff = (tLoop_02 - tLoop_01).total_seconds()
+ else:
+ tDiff = (tLoop_01 - tLoop_02).total_seconds()
+
+ arrTimeMinDiff.append(int(tDiff / 60))
+ arrTimeMinDiff.append(24 * 60 - int(tDiff / 60))
+
+print (min(arrTimeMinDiff))
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))