You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4 vuotta sitten
123456789101112131415161718192021222324252627282930
  1. import re
  2. import sys
  3. def checks(byr, iyr, eyr, hgt, hcl, ecl, pid, cid=None):
  4. yield 1920 <= int(byr) <= 2002
  5. yield 2010 <= int(iyr) <= 2020
  6. yield 2020 <= int(eyr) <= 2030
  7. if hgt.endswith('cm'):
  8. yield 150 <= int(hgt[:-2]) <= 193
  9. elif hgt.endswith('in'):
  10. yield 59 <= int(hgt[:-2]) <= 76
  11. else:
  12. yield False
  13. yield re.match(r'^#[0-9a-f]{6}$', hcl)
  14. yield re.match(r'^(amb|blu|brn|gry|grn|hzl|oth)$', ecl)
  15. yield re.match(r'^\d{9}$', pid)
  16. ans1 = 0
  17. ans2 = 0
  18. fields = {'byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid'}
  19. for blob in sys.stdin.read().split('\n\n'):
  20. passport = dict(re.findall(r'(\S+):(\S+)', blob))
  21. valid = not fields.difference(passport)
  22. ans1 += valid
  23. if valid:
  24. ans2 += all(checks(**passport))
  25. print(ans1)
  26. print(ans2)