Created
December 2, 2020 11:04
-
-
Save rtt/6380a5404728b495ce2d49eb85f6ba8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def get_input(): | |
with open('2.txt') as f: | |
passwords = f.readlines() | |
return map(str.strip, passwords) | |
def get_password_specs(specs): | |
s = [] | |
for p in specs: | |
spec, letter, password = p.split(' ') | |
spec = list(map(int, spec.partition('-')[0:3:2])) | |
s.append({'letter': letter[:1], 'spec': spec, 'password': password}) | |
return s | |
def valid_pwd(p): | |
return p['spec'][0] <= Counter(p['password'])[p['letter']] <= p['spec'][1] | |
def run(): | |
print(len([p for p in get_password_specs(get_input()) if valid_pwd(p)])) | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment