32 lines
1 KiB
Python
32 lines
1 KiB
Python
|
input_file = "/tmp/aocinput"
|
||
|
|
||
|
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")
|
||
|
|
||
|
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()
|
||
|
|
||
|
print(f"There are {valid_passwords} valid passwords")
|