47 lines
909 B
Python
Executable File
47 lines
909 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Advent Of Code 2020 - Day 4
|
|
|
|
"""
|
|
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
|
|
byr:1937 iyr:2017 cid:147 hgt:183cm
|
|
|
|
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
|
|
hcl:#cfa07d byr:1929
|
|
|
|
hcl:#ae17e1 iyr:2013
|
|
eyr:2024
|
|
ecl:brn pid:760753108 byr:1931
|
|
hgt:179cm
|
|
|
|
hcl:#cfa07d eyr:2025 pid:166559648
|
|
iyr:2011 ecl:brn hgt:59in
|
|
"""
|
|
|
|
filename = "input.txt"
|
|
|
|
import re
|
|
|
|
def parsePassport(passport):
|
|
passportDict = dict()
|
|
for item in re.split(' |\n', passport):
|
|
passportDict[item.split(':')[0]] = item.split(':')[1]
|
|
return passportDict
|
|
|
|
def validatePassport(passport):
|
|
return all(key in passport for key in ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"])
|
|
|
|
|
|
with open(filename) as f:
|
|
data = [(x.strip()) for x in f.read().split("\n\n")]
|
|
|
|
count = 0
|
|
|
|
for passport in data:
|
|
|
|
if validatePassport(parsePassport(passport)):
|
|
count = count + 1
|
|
|
|
print (count)
|
|
|