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
18
day_2/part_1.py
Normal file
18
day_2/part_1.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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(" ")
|
||||
min_len, max_len = rules[0].split("-")
|
||||
|
||||
if int(min_len) <= len(re.findall(rules[1], password)) <= int(max_len):
|
||||
valid_passwords += 1
|
||||
|
||||
print(valid_passwords)
|
||||
Loading…
Add table
Add a link
Reference in a new issue