diff options
Diffstat (limited to 'challenge-282/eric-cheung/python')
| -rwxr-xr-x | challenge-282/eric-cheung/python/ch-1.py | 25 | ||||
| -rwxr-xr-x | challenge-282/eric-cheung/python/ch-2.py | 8 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-282/eric-cheung/python/ch-1.py b/challenge-282/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..ae1092136a --- /dev/null +++ b/challenge-282/eric-cheung/python/ch-1.py @@ -0,0 +1,25 @@ +
+def GetGoodInteger (nFuncInput):
+ strInput = str(nFuncInput)
+
+ if len(strInput) < 3:
+ return "-1"
+
+ if len(strInput) == 3:
+ return (strInput if len(set(strInput)) == 1 else "-1")
+
+ for nIndx in range(len(strInput) - 3):
+
+ bFirstFlag = (True if nIndx == 0 else len(set(strInput[nIndx - 1:nIndx + 3])) > 1)
+ bLastFlag = (True if nIndx == len(strInput) - 2 else len(set(strInput[nIndx:nIndx + 4])) > 1)
+
+ if bFirstFlag and len(set(strInput[nIndx:nIndx + 3])) == 1 and bLastFlag:
+ return strInput[nIndx:nIndx + 3]
+
+ return "-1"
+
+## nInput = 12344456 ## Example 1
+## nInput = 1233334 ## Example 2
+nInput = 10020003 ## Example 3
+
+print (GetGoodInteger(nInput))
diff --git a/challenge-282/eric-cheung/python/ch-2.py b/challenge-282/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..9c2845a71f --- /dev/null +++ b/challenge-282/eric-cheung/python/ch-2.py @@ -0,0 +1,8 @@ +
+## strInput = "pPeERrLl" ## Example 1
+## strInput = "rRr" ## Example 2
+strInput = "GoO" ## Example 3
+
+arrCount = [0 if strInput[nIndx].lower() == strInput[nIndx + 1].lower() else 1 for nIndx in range(len(strInput) - 1)]
+
+print (sum(arrCount))
|
