Skip to content

Instantly share code, notes, and snippets.

@rtt
Last active December 3, 2020 14:03
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/2388532bbe6e26c8c5aad21253450391 to your computer and use it in GitHub Desktop.
Save rtt/2388532bbe6e26c8c5aad21253450391 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, 'pwd': password})
return s
def valid_pwd(p):
idx1, idx2 = p['spec']
return (p['pwd'][idx1-1] == p['letter']) != (p['pwd'][idx2-1] == p['letter'])
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