diff options
| author | James Smith <js5@sanger.ac.uk> | 2022-12-26 14:20:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-26 14:20:09 +0000 |
| commit | ae146d8ac3d7fd8a856be32a4367693d574d914d (patch) | |
| tree | df39baa009d2f572ebc6a3d2d1f5cc0a953d60e7 /challenge-196/eric-cheung/python | |
| parent | dae0a10e23b470229e2440cd0683b3a90a1e4ca4 (diff) | |
| parent | 63fb76188e132564e50feefd2d9d5b8491568948 (diff) | |
| download | perlweeklychallenge-club-ae146d8ac3d7fd8a856be32a4367693d574d914d.tar.gz perlweeklychallenge-club-ae146d8ac3d7fd8a856be32a4367693d574d914d.tar.bz2 perlweeklychallenge-club-ae146d8ac3d7fd8a856be32a4367693d574d914d.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-196/eric-cheung/python')
| -rwxr-xr-x | challenge-196/eric-cheung/python/ch-1.py | 18 | ||||
| -rwxr-xr-x | challenge-196/eric-cheung/python/ch-2.py | 25 |
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))
|
