2020-12-05 00:04:09 +01:00
|
|
|
input_file = "input.txt"
|
|
|
|
|
2020-12-04 23:10:35 +01:00
|
|
|
|
|
|
|
def letter_count():
|
|
|
|
valid_passwords = 0
|
|
|
|
|
|
|
|
with open(input_file) as passwords:
|
|
|
|
line = passwords.readline()
|
|
|
|
while line and line != "\n":
|
|
|
|
elements = line.split(" ")
|
|
|
|
min_req, max_req = elements[0].split("-")
|
|
|
|
password_count = elements[2].count(elements[1][0])
|
|
|
|
if int(min_req) <= password_count <= int(max_req):
|
|
|
|
valid_passwords += 1
|
|
|
|
|
|
|
|
line = passwords.readline()
|
|
|
|
|
|
|
|
print(f"There are {valid_passwords} valid passwords")
|
|
|
|
|
2020-12-05 00:04:09 +01:00
|
|
|
|
2020-12-04 23:10:35 +01:00
|
|
|
def letter_position():
|
|
|
|
valid_passwords = 0
|
|
|
|
|
|
|
|
with open(input_file) as passwords:
|
|
|
|
line = passwords.readline()
|
|
|
|
while line and line != "\n":
|
|
|
|
elements = line.split(" ")
|
|
|
|
first_pos, second_pos = elements[0].split("-")
|
|
|
|
if (elements[2][int(first_pos) - 1] == elements[1][0]) ^ (elements[2][int(second_pos) - 1] == elements[1][0]):
|
|
|
|
valid_passwords += 1
|
|
|
|
|
|
|
|
line = passwords.readline()
|
|
|
|
|
2020-12-05 00:04:09 +01:00
|
|
|
print(f"There are {valid_passwords} valid passwords")
|