From b68fe4b8bfc540612fb0f86d94ae39162039081e Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 20 Dec 2022 09:54:50 +0000 Subject: - Added solutions by David Ferrone. - Added solutions by Niels van Dijke. - Added solutions by Dave Jacoby. - Added solutions by Peter Campbell Smith. - Added solutions by Bob Lied. - Added solutions by W. Luis Mochan. - Added solutions by Carlos Oliveira. - Added solutions by Eric Cheung. --- challenge-196/eric-cheung/python/ch-1.py | 18 ++++++++++++++++++ challenge-196/eric-cheung/python/ch-2.py | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 challenge-196/eric-cheung/python/ch-1.py create mode 100755 challenge-196/eric-cheung/python/ch-2.py (limited to 'challenge-196/eric-cheung/python') 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)) -- cgit