Skip to content

Instantly share code, notes, and snippets.

@rtt
Created December 2, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtt/6380a5404728b495ce2d49eb85f6ba8d to your computer and use it in GitHub Desktop.
Save rtt/6380a5404728b495ce2d49eb85f6ba8d to your computer and use it in GitHub Desktop.
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