add day two part two
This commit is contained in:
parent
3de439fa41
commit
a7c3b873c9
@ -64,9 +64,14 @@ def parse_policy(input_string: str) -> Dict[str, int]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def verify_password(policy, password) -> bool:
|
def verify_password(policy, password, part_two_rules: bool = True) -> bool:
|
||||||
counter = Counter(password)
|
if not part_two_rules:
|
||||||
return policy['lower_bound'] <= counter[policy['char']] <= policy['upper_bound']
|
counter = Counter(password)
|
||||||
|
return policy['lower_bound'] <= counter[policy['char']] <= policy['upper_bound']
|
||||||
|
else:
|
||||||
|
lb, ub = policy['lower_bound'], policy['upper_bound']
|
||||||
|
# 1 indexed, ^ == XOR
|
||||||
|
return (password[lb - 1] == policy['char']) ^ (password[ub - 1] == policy['char'])
|
||||||
|
|
||||||
|
|
||||||
def count_valid_passwords(parsed_passwords: List[Tuple[Dict, str]]):
|
def count_valid_passwords(parsed_passwords: List[Tuple[Dict, str]]):
|
||||||
|
Loading…
Reference in New Issue
Block a user