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.
55 lines
1.3 KiB
55 lines
1.3 KiB
#!/usr/bin/env python3
|
|
|
|
from sys import argv
|
|
|
|
p = [{e.split(":")[0]: e.split(":")[1] for e in l.replace("\n", " ").split()} for l in open(argv[1]).read().split("\n\n")]
|
|
|
|
fi = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]
|
|
|
|
ok = 0
|
|
ok2 = 0
|
|
for cp in p:
|
|
for cf in fi:
|
|
if cf not in cp:
|
|
break
|
|
else:
|
|
ok += 1
|
|
|
|
hgt_u = cp["hgt"][-2:]
|
|
try:
|
|
byr = int(cp["byr"])
|
|
iyr = int(cp["iyr"])
|
|
eyr = int(cp["eyr"])
|
|
hgt = int(cp["hgt"][:-2])
|
|
pid = int(cp["pid"])
|
|
except:
|
|
continue
|
|
|
|
if byr < 1920 or byr > 2002:
|
|
continue
|
|
if iyr < 2010 or iyr > 2020:
|
|
continue
|
|
if eyr < 2020 or eyr > 2030:
|
|
continue
|
|
if hgt_u == "cm":
|
|
if hgt < 150 or hgt > 193:
|
|
continue
|
|
elif hgt_u == "in":
|
|
if hgt < 59 or hgt > 76:
|
|
continue
|
|
else:
|
|
continue
|
|
if len(cp["hcl"]) != 7 or cp["hcl"][0] != '#':
|
|
continue
|
|
for c in cp["hcl"][1:]:
|
|
if c not in "0123456789abcdef":
|
|
continue
|
|
if cp["ecl"] not in ["amb","blu","brn","gry","grn","hzl","oth"]:
|
|
continue
|
|
if len(cp["pid"]) != 9:
|
|
continue
|
|
|
|
ok2 += 1
|
|
|
|
print(ok)
|
|
print(ok2)
|
|
|