Validity fluidity

cat-town
Dan Buch 4 years ago
parent 9128f6bdc4
commit 17c3ee9316
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -16,20 +16,23 @@ def main() -> int:
class Policy: class Policy:
def __init__(self, char: str, min_count: int, max_count: int): def __init__(self, char: str, pos1: int, pos2: int):
self.char = char self.char = char
self.min_count = min_count self.pos1 = pos1
self.max_count = max_count self.pos2 = pos2
@classmethod @classmethod
def fromstring(cls, input_string) -> "Policy": def fromstring(cls, input_string) -> "Policy":
parts = [s.strip() for s in input_string.split(" ")][:2] parts = [s.strip() for s in input_string.split(" ")][:2]
min_max = [int(s) for s in parts[0].split("-")][:2] pos = [int(s) for s in parts[0].split("-")][:2]
return cls(parts[1], min_max[0], min_max[1]) return cls(parts[1], pos[0], pos[1])
def is_valid(self, password: str) -> bool: def is_valid(self, password: str) -> bool:
actual = password.count(self.char) matches = 0
return actual >= self.min_count and actual <= self.max_count for pos in (self.pos1 - 1, self.pos2 - 1):
if password[pos] == self.char:
matches += 1
return matches == 1
class PolicyPassword: class PolicyPassword:

Loading…
Cancel
Save