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
25
day_4/part_1.py
Normal file
25
day_4/part_1.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
with open("input") as f:
|
||||
data = [x.replace("\n", " ") for x in f.read().split("\n\n")]
|
||||
|
||||
# The fields that passports have, if True, it's required, if False, it's an
|
||||
# optional field
|
||||
fields = {
|
||||
"byr": True,
|
||||
"iyr": True,
|
||||
"eyr": True,
|
||||
"hgt": True,
|
||||
"hcl": True,
|
||||
"ecl": True,
|
||||
"pid": True,
|
||||
"cid": False
|
||||
}
|
||||
|
||||
valid_passports = len(data)
|
||||
|
||||
for passport in data:
|
||||
for field, required in fields.items():
|
||||
if field not in passport and required:
|
||||
valid_passports -= 1
|
||||
break
|
||||
|
||||
print(f"Valid Passports: {valid_passports}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue