aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2024-09-22 17:27:47 +1000
committerSimon Green <mail@simon.green>2024-09-22 17:27:47 +1000
commit9e99d7529d22b326148431954541f6ffdd76497f (patch)
treedc71892d439a9be723f4ae8ef394d12d7a55daaf /challenge-287/sgreen/python/ch-1.py
parent68e321dd32a834f54b55d5e8924f04358e41cf1f (diff)
downloadperlweeklychallenge-club-9e99d7529d22b326148431954541f6ffdd76497f.tar.gz
perlweeklychallenge-club-9e99d7529d22b326148431954541f6ffdd76497f.tar.bz2
perlweeklychallenge-club-9e99d7529d22b326148431954541f6ffdd76497f.zip
sgreen solutions to challenge 287
Diffstat (limited to 'challenge-287/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-287/sgreen/python/ch-1.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/challenge-287/sgreen/python/ch-1.py b/challenge-287/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..54a595cdc6
--- /dev/null
+++ b/challenge-287/sgreen/python/ch-1.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+
+def strong_password(password: str) -> int:
+ """The minimum number of steps required to make the given string very strong password.
+
+ Args:
+ password (str): The supplied password.
+
+ Returns:
+ int: The minimum number of steps required.
+ """
+
+ # Count consecutive characters
+ cons_count = 0
+ for c in re.findall(r'((.)\2{2,})', password):
+ # For every 3 consecutive characters, we need to replace one
+ cons_count += len(c[0]) // 3
+
+ # Additional characters require to make it at least 6 characters
+ char_count = max(0, 6 - len(password))
+
+ # Count the number of missing character types
+ type_count = 0
+ if not re.search(r'[a-z]', password):
+ type_count += 1
+ if not re.search(r'[A-Z]', password):
+ type_count += 1
+ if not re.search(r'[0-9]', password):
+ type_count += 1
+
+ # Since the type change can be covered by one of the other required
+ # changes, return the maximum of the two
+ return max(cons_count + char_count, type_count)
+
+
+def main():
+ result = strong_password(sys.argv[1])
+ print(result)
+
+
+if __name__ == '__main__':
+ main()