diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2024-09-18 19:56:42 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2024-09-18 19:56:42 -0400 |
| commit | f86f5e2fec16020c1d86f9028fb0f61cfeac106e (patch) | |
| tree | 0fd388a696b51ffde5a7bfe8519a74e1caf42461 /challenge-287/eric-cheung/python/ch-1.py | |
| parent | ff8719c86653d5ad3121955e9494a0010527c2b9 (diff) | |
| parent | 0052ec63ca70eaa6d9ffb1926c294dbfd85f8c05 (diff) | |
| download | perlweeklychallenge-club-f86f5e2fec16020c1d86f9028fb0f61cfeac106e.tar.gz perlweeklychallenge-club-f86f5e2fec16020c1d86f9028fb0f61cfeac106e.tar.bz2 perlweeklychallenge-club-f86f5e2fec16020c1d86f9028fb0f61cfeac106e.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-287/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-287/eric-cheung/python/ch-1.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/challenge-287/eric-cheung/python/ch-1.py b/challenge-287/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..63e1bc3931 --- /dev/null +++ b/challenge-287/eric-cheung/python/ch-1.py @@ -0,0 +1,58 @@ +
+## strInput = "a" ## Example 1
+## strInput = "aB2" ## Example 2
+## strInput = "PaaSW0rd" ## Example 3
+## strInput = "Paaasw0rd" ## Example 4
+strInput = "aaaaa" ## Example 5
+
+nDupChar = 3
+
+nLenCharAdd = (0 if len(strInput) >= 6 else 6 - len(strInput))
+
+nLenUpperAdd = (0 if any(strLoop.isupper() for strLoop in strInput) else 1)
+nLenLowerAdd = (0 if any(strLoop.islower() for strLoop in strInput) else 1)
+nIsNumericAdd = (0 if any(strLoop.isnumeric() for strLoop in strInput) else 1)
+
+nCharSumAdd = sum([nLenUpperAdd, nLenLowerAdd, nIsNumericAdd])
+
+## ==
+arrList = list(strInput)
+arrUniqList = set(arrList)
+arrDupList = [charLoop for charLoop in set(arrList) if arrList.count(charLoop) >= 3]
+
+arrCheckList = []
+arrSubCheckList = []
+arrCheckIndx = []
+for nIndx, charLoop in enumerate(arrList):
+ if charLoop not in arrDupList:
+ continue
+
+ if len(arrSubCheckList) == 0:
+ arrSubCheckList.append([charLoop, [nIndx]])
+ elif arrSubCheckList[-1][0] == charLoop and nIndx - arrSubCheckList[-1][1][-1] == 1:
+ arrSubCheckList[-1][1].append(nIndx)
+ else:
+ arrCheckList = arrCheckList + arrSubCheckList
+ arrSubCheckList = []
+ arrSubCheckList.append([charLoop, [nIndx]])
+
+if len(arrSubCheckList) > 0:
+ arrCheckList = arrCheckList + arrSubCheckList
+ arrSubCheckList = []
+
+for arrLoop in arrCheckList:
+ if len(arrLoop[1]) < nDupChar:
+ continue
+
+ for nSubIndx in range(nDupChar - 1, len(arrLoop[1]), nDupChar):
+ arrCheckIndx.append(nSubIndx)
+
+nLenChange = len(arrCheckIndx)
+## ==
+
+nTemp = (nCharSumAdd - nLenCharAdd if nCharSumAdd >= nLenCharAdd else 0)
+nTemp = (nTemp - nLenChange if nTemp >= nLenChange else 0)
+
+nTotalSteps = nLenCharAdd + nLenChange + nTemp
+
+print (nTotalSteps)
|
