2020 AoC, Days 1-4
This commit is contained in:
commit
ad04dffb69
9 changed files with 2782 additions and 0 deletions
32
2020/Day 2/Solution.py
Normal file
32
2020/Day 2/Solution.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
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")
|
1000
2020/Day 2/input.txt
Normal file
1000
2020/Day 2/input.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue