From 005501546fd858f28f05dd1f7912912329d1532c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 4 Dec 2020 09:50:23 +0100 Subject: [PATCH] 2020: d04: ex1: add solution --- 2020/d04/ex1/ex1.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 2020/d04/ex1/ex1.py diff --git a/2020/d04/ex1/ex1.py b/2020/d04/ex1/ex1.py new file mode 100755 index 0000000..5193652 --- /dev/null +++ b/2020/d04/ex1/ex1.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import sys +from typing import List + + +def validate(passport: List[str]) -> int: + fields = [ + "byr", + "iyr", + "eyr", + "hgt", + "hcl", + "ecl", + "pid", + ] + for field in fields: + if field not in passport: + return False + return True + + +def solve(passport_fields: List[List[str]]) -> int: + return sum(validate(passport) for passport in passport_fields) + + +def main() -> None: + passports: List[List[str]] = [[]] + for line in sys.stdin: + if line == "\n" or line == "": + passports.append([]) + continue + passports[-1] += [s.split(":")[0] for s in line.split(" ")] + print(solve(passports)) + + +if __name__ == "__main__": + main()