aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manring <michael@manring>2024-09-18 18:59:14 +1000
committerMichael Manring <michael@manring>2024-09-18 18:59:14 +1000
commitdec6ffda02fa8185821c764226115e377c869908 (patch)
tree2a04841be0ab30214b0328b8f770e9c422aa03eb
parent0107fbd7b814cabe19b82c89b4115282d85df92b (diff)
downloadperlweeklychallenge-club-dec6ffda02fa8185821c764226115e377c869908.tar.gz
perlweeklychallenge-club-dec6ffda02fa8185821c764226115e377c869908.tar.bz2
perlweeklychallenge-club-dec6ffda02fa8185821c764226115e377c869908.zip
pwc287 solution - refactored ch-1.py
-rw-r--r--challenge-287/pokgopun/python/ch-1.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/challenge-287/pokgopun/python/ch-1.py b/challenge-287/pokgopun/python/ch-1.py
index c63ef17bee..48421e37f3 100644
--- a/challenge-287/pokgopun/python/ch-1.py
+++ b/challenge-287/pokgopun/python/ch-1.py
@@ -52,33 +52,27 @@ Task 2: Valid Number
"""
### solution by pokgopun@gmail.com
-def strongPassword(passwd: str):
- cRpt = 0
- prev,crpt = "", 0
- hasDgt,hasUc,hasLc = False, False, False
- for c in passwd:
- if ord(c) >= 48 and ord(c) <= 57:
- hasDgt = True
- if ord(c) >= 65 and ord(c) <= 90:
- hasUc = True
- if ord(c) >= 97 and ord(c) <= 122:
- hasLc = True
+def strongPassword(pwd: str):
+ requiredCharset = dict.fromkeys(("09","AZ","az"), True)
+ countConsecutiveChar = 0
+ prev = ""
+ count = 0
+ for c in pwd:
+ for charset in requiredCharset.keys():
+ if requiredCharset[charset] and c >= charset[0] and c <= charset[1]:
+ requiredCharset[charset] = False
if prev == c:
- crpt += 1
- if crpt==3:
- cRpt += 1
- crpt = 0
+ count += 1
+ if count == 3:
+ countConsecutiveChar += 1
prev = ""
else:
prev = c
- crpt = 1
- cHas = 0
- for lgc in (hasDgt,hasUc,hasLc):
- if lgc == False:
- cHas += 1
- mChr = 6 - min(6,len(passwd))
- #print(mChr,cHas,cRpt)
- return max(mChr, cHas, cRpt)
+ count = 1
+ countRequiredCharset = sum(requiredCharset.values())
+ countRequiredAddition = 6 - min(6, len(pwd))
+ #print(countRequiredAddition, countConsecutiveChar, countRequiredCharset)
+ return max(countRequiredAddition, countConsecutiveChar, countRequiredCharset)
import unittest