Day 4
This commit is contained in:
24
day04/part1.py
Normal file
24
day04/part1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import re
|
||||
|
||||
lines = (list(map(lambda a: a.split(':'), x.strip().split())) for x in open("input.txt"))
|
||||
|
||||
passport = {}
|
||||
count = 0
|
||||
must_have = {'iyr', 'hcl', 'hgt', 'pid', 'ecl', 'eyr', 'byr'}
|
||||
|
||||
|
||||
def check_passport(pp):
|
||||
valid = len(set(pp).intersection(must_have)) == len(must_have)
|
||||
if not valid:
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
||||
for line in lines:
|
||||
if len(line) == 0:
|
||||
count += check_passport(passport)
|
||||
passport = {}
|
||||
for key, val in line:
|
||||
passport[key] = val
|
||||
count += check_passport(passport)
|
||||
print(count)
|
||||
Reference in New Issue
Block a user