X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2020.git/blobdiff_plain/a2ce7bb47964e226d4b10b791a038ca1f1fa67d7..fe0197cb1dc8f701b69ce52b9acb445351557c8d:/day04/count_valid_passports.py?ds=sidebyside diff --git a/day04/count_valid_passports.py b/day04/count_valid_passports.py new file mode 100644 index 0000000..3ea48a8 --- /dev/null +++ b/day04/count_valid_passports.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +REQUIRED_FIELDS=(('byr', "Birth Year"),('iyr', "Issue Year"),('eyr', "Expiration Year"),('hgt', "Height"),('hcl', "Hair Colour"),('ecl', "Eye Colour"),('pid',"Passport ID")) +OPTIONAL_FIELDS=(('cid', "Country ID")) + +def check_passport(passport_data): + print(passport_data) + for field in REQUIRED_FIELDS: + if field[0] not in passport_data: + return False + return True + +def main(): + new_passport=False + passport_data=dict() + valid_passports=0 + for line in open("input.txt"): + if new_passport: + if check_passport(passport_data): + valid_passports += 1 + passport_data.clear() + line=line.rstrip() + if line == '': + new_passport=True + continue + new_passport=False + parts=line.split(" ") + for part in parts: + (key, value) = part.split(":") + passport_data[key] = value + if not new_passport: + if check_passport(passport_data): + valid_passports += 1 + print("Found", valid_passports, "valid passports") + +main()