aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manring <michael@manring>2024-09-20 00:33:30 +1000
committerMichael Manring <michael@manring>2024-09-20 00:33:30 +1000
commit4282aa11920a4187a1f43423b1a6cf90bbd7d692 (patch)
tree03d3bb835aff4c08c24d6daca4333c78dc8c6b01
parent5012dcad6894d03af2de370e992d9e99e1aae721 (diff)
downloadperlweeklychallenge-club-4282aa11920a4187a1f43423b1a6cf90bbd7d692.tar.gz
perlweeklychallenge-club-4282aa11920a4187a1f43423b1a6cf90bbd7d692.tar.bz2
perlweeklychallenge-club-4282aa11920a4187a1f43423b1a6cf90bbd7d692.zip
pwc287 - some enhancement on ch-1.py
-rw-r--r--challenge-287/pokgopun/python/ch-1.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/challenge-287/pokgopun/python/ch-1.py b/challenge-287/pokgopun/python/ch-1.py
index 48421e37f3..70ce8f75a5 100644
--- a/challenge-287/pokgopun/python/ch-1.py
+++ b/challenge-287/pokgopun/python/ch-1.py
@@ -54,22 +54,33 @@ Task 2: Valid Number
def strongPassword(pwd: str):
requiredCharset = dict.fromkeys(("09","AZ","az"), True)
- countConsecutiveChar = 0
- prev = ""
- count = 0
+ countRequiredCharset = len(requiredCharset)
+ #n = 0
for c in pwd:
+ #n += 1
for charset in requiredCharset.keys():
if requiredCharset[charset] and c >= charset[0] and c <= charset[1]:
requiredCharset[charset] = False
- if prev == c:
- count += 1
- if count == 3:
- countConsecutiveChar += 1
- prev = ""
- else:
- prev = c
- count = 1
- countRequiredCharset = sum(requiredCharset.values())
+ countRequiredCharset -= 1
+ break
+ if countRequiredCharset==0:
+ break
+ #print(n,"char(s) checked for required charsets")
+ countConsecutiveChar = 0
+ consecutiveCharLength = 3
+ if len(pwd) >= consecutiveCharLength:
+ prev = ""
+ count = 0
+ for c in pwd:
+ #print(c,"<=>",prev)
+ if prev == c:
+ count += 1
+ if count == consecutiveCharLength:
+ countConsecutiveChar += 1
+ prev = ""
+ else:
+ prev = c
+ count = 1
countRequiredAddition = 6 - min(6, len(pwd))
#print(countRequiredAddition, countConsecutiveChar, countRequiredCharset)
return max(countRequiredAddition, countConsecutiveChar, countRequiredCharset)