Add advent code for 2020 days 1-4
This commit is contained in:
parent
2c466792a4
commit
948009891a
12 changed files with 256 additions and 0 deletions
21
day_2/part_2.py
Normal file
21
day_2/part_2.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
with open("input") as file:
|
||||
data = file.read().split("\n")
|
||||
|
||||
import re
|
||||
|
||||
valid_passwords = 0
|
||||
|
||||
|
||||
for password_data in data:
|
||||
|
||||
rule, password = password_data.split(": ")
|
||||
rules = rule.split(" ")
|
||||
char = rules[1]
|
||||
pos1, pos2 = rules[0].split("-")
|
||||
|
||||
if password[int(pos1)-1] == char and not password[int(pos2)-1] == char:
|
||||
valid_passwords += 1
|
||||
if not password[int(pos1)-1] == char and password[int(pos2)-1] == char:
|
||||
valid_passwords += 1
|
||||
|
||||
print(valid_passwords)
|
||||
Loading…
Add table
Add a link
Reference in a new issue