diff options
| -rwxr-xr-x | challenge-194/eric-cheung/python/ch-1.py | 34 | ||||
| -rwxr-xr-x | challenge-194/eric-cheung/python/ch-2.py | 24 |
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-194/eric-cheung/python/ch-1.py b/challenge-194/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..c8df0f3507 --- /dev/null +++ b/challenge-194/eric-cheung/python/ch-1.py @@ -0,0 +1,34 @@ +
+## strTimeInput = "?5:00" ## Example 1
+## strTimeInput = "?3:00" ## Example 2
+## strTimeInput = "1?:00" ## Example 3
+## strTimeInput = "2?:00" ## Example 4
+## strTimeInput = "12:?5" ## Example 5
+strTimeInput = "12:5?" ## Example 6
+
+nPos = strTimeInput.find("?")
+
+if nPos == 0:
+ for nLoop in [2, 1]:
+ nHour = int(str(nLoop) + strTimeInput[1])
+ if nHour <= 23:
+ print (str(nLoop))
+ break
+elif nPos == 1:
+ for nLoop in [9, 8, 7, 6, 5, 4, 3, 2, 1]:
+ nHour = int(strTimeInput[0] + str(nLoop))
+ if nHour <= 23:
+ print (str(nLoop))
+ break
+elif nPos == 3:
+ for nLoop in [5, 4, 3, 2, 1]:
+ nMin = int(str(nLoop) + strTimeInput[4])
+ if nMin <= 59:
+ print (str(nLoop))
+ break
+elif nPos == 4:
+ for nLoop in [9, 8, 7, 6, 5, 4, 3, 2, 1]:
+ nMin = int(strTimeInput[3] + str(nLoop))
+ if nMin <= 59:
+ print (str(nLoop))
+ break
diff --git a/challenge-194/eric-cheung/python/ch-2.py b/challenge-194/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..8d04f9bf27 --- /dev/null +++ b/challenge-194/eric-cheung/python/ch-2.py @@ -0,0 +1,24 @@ +
+## strInput = "abbc" ## Example 1
+## strInput = "xyzyyxz" ## Example 2
+strInput = "xzxz" ## Example 3
+
+arrStr = [*strInput]
+arrUniqStr = list(set(arrStr))
+
+arrCount = []
+arrUniqCount = []
+
+for charLoop in arrUniqStr:
+ arrCount.append(arrStr.count(charLoop))
+
+## print (arrCount)
+
+arrUniqCount = list(set(arrCount))
+
+if len(arrUniqCount) == 1 or len(arrUniqCount) > 2:
+ print ("0")
+elif abs(arrUniqCount[0] - arrUniqCount[1]) == 1:
+ print ("1")
+else:
+ print ("0")
|
