aboutsummaryrefslogtreecommitdiff
path: root/challenge-196/eric-cheung/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-196/eric-cheung/python/ch-2.py')
-rwxr-xr-xchallenge-196/eric-cheung/python/ch-2.py25
1 files changed, 25 insertions, 0 deletions
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))