diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-18 20:01:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-18 20:01:20 +0100 |
| commit | 52fb345c4183e41c998ae27b202cfcf90f6fbcdc (patch) | |
| tree | 33f6c411efb236d0872066ebfd1dd9aa63ca6161 | |
| parent | 71bb52493fba129f3633f98609052779421d263c (diff) | |
| parent | dec6ffda02fa8185821c764226115e377c869908 (diff) | |
| download | perlweeklychallenge-club-52fb345c4183e41c998ae27b202cfcf90f6fbcdc.tar.gz perlweeklychallenge-club-52fb345c4183e41c998ae27b202cfcf90f6fbcdc.tar.bz2 perlweeklychallenge-club-52fb345c4183e41c998ae27b202cfcf90f6fbcdc.zip | |
Merge pull request #10863 from pokgopun/pwc287
pwc287 solution - refactored ch-1.py
| -rw-r--r-- | challenge-287/pokgopun/python/ch-1.py | 40 |
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 |
