aboutsummaryrefslogtreecommitdiff
path: root/challenge-196/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-196/eric-cheung/python')
-rwxr-xr-xchallenge-196/eric-cheung/python/ch-1.py18
-rwxr-xr-xchallenge-196/eric-cheung/python/ch-2.py25
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-196/eric-cheung/python/ch-1.py b/challenge-196/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..21c764d00a
--- /dev/null
+++ b/challenge-196/eric-cheung/python/ch-1.py
@@ -0,0 +1,18 @@
+
+from itertools import combinations
+
+def get_Pattern132_List(arrInput):
+
+ nIndxTuple = combinations(range(0, len(arrInput)), 3)
+
+ for nIndxLoop_01, nIndxLoop_02, nIndxLoop_03 in list(nIndxTuple):
+ ## if arrInput[nIndxLoop_01] < arrInput[nIndxLoop_03] and arrInput[nIndxLoop_03] < arrInput[nIndxLoop_02]:
+ if arrInput[nIndxLoop_01] < arrInput[nIndxLoop_03] < arrInput[nIndxLoop_02]:
+ return [arrInput[nIndxLoop_01], arrInput[nIndxLoop_02], arrInput[nIndxLoop_03]]
+
+arrInputList = [3, 1, 4, 2] ## Example 1
+## arrInputList = [1, 2, 3, 4] ## Example 2
+## arrInputList = [1, 3, 2, 4, 6, 5] ## Example 3
+## arrInputList = [1, 3, 4, 2] ## Example 4
+
+print (get_Pattern132_List(arrInputList))
diff --git a/challenge-196/eric-cheung/python/ch-2.py b/challenge-196/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..0ffa45d67b
--- /dev/null
+++ b/challenge-196/eric-cheung/python/ch-2.py
@@ -0,0 +1,25 @@
+
+def getRangeList(arrInput):
+
+ nStart = arrInput[0]
+ nEnd = arrInput[0]
+
+ arrOutput = []
+
+ for nIndxLoop in range(1, len(arrInput)):
+ if arrInput[nIndxLoop] == arrInput[nIndxLoop - 1] + 1:
+ nEnd = arrInput[nIndxLoop]
+ if nIndxLoop == len(arrInput) - 1:
+ arrOutput.append([nStart, nEnd])
+ else:
+ if nEnd > nStart:
+ arrOutput.append([nStart, nEnd])
+ nStart = arrInput[nIndxLoop]
+
+ return arrOutput
+
+arrInputList = [1, 3, 4, 5, 7] ## Example 1
+## arrInputList = [1, 2, 3, 6, 7, 9] ## Example 2
+## arrInputList = [0, 1, 2, 4, 5, 6, 8, 9] ## Example 3
+
+print (getRangeList(arrInputList))