This commit is contained in:
Søren Rasmussen 2020-12-02 09:19:42 +01:00
parent 9b86c7f46d
commit dfca8fceab
2 changed files with 1028 additions and 0 deletions

1000
2020/2/data.txt Normal file

File diff suppressed because it is too large Load diff

28
2020/2/main.py Normal file
View file

@ -0,0 +1,28 @@
import re
re_pw = re.compile(r"^(?P<min>\d+)-(?P<max>\d+)\s+(?P<key>\S): (?P<password>.+)$")
num_valid = 0
num_valid_2 = 0
with open("data.txt", "r", encoding="utf-8") as f:
for l in f:
m = re_pw.match(l)
assert m, "wtf?"
min_letters = int(m.group("min"))
max_letters = int(m.group("max"))
pw = m.group("password")
key = m.group("key")
is_valid = min_letters <= pw.count(key) <= max_letters
if is_valid:
num_valid += 1
is_valid_2 = bool(pw[min_letters-1] == key) != bool(pw[max_letters-1] == key)
if is_valid_2:
num_valid_2 += 1
print(f"{l.rstrip()}\t{is_valid}\t{is_valid_2}")
print(f"\nNum valid pwds (1): {num_valid}")
print(f"\nNum valid pwds (2): {num_valid_2}")