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:
|
||||
counter = Counter(password)
|
||||
return policy['lower_bound'] <= counter[policy['char']] <= policy['upper_bound']
|
||||
def verify_password(policy, password, part_two_rules: bool = True) -> bool:
|
||||
if not part_two_rules:
|
||||
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]]):
|
||||
|
Loading…
Reference in New Issue
Block a user