|
|
@@ -14,10 +14,70 @@ for t in tmp:
|
|
|
count += 1
|
|
|
else:
|
|
|
#print(t)
|
|
|
- items[count] += t
|
|
|
+ items[count] += ' '+t
|
|
|
|
|
|
valid = 0
|
|
|
|
|
|
+def isvalid(item):
|
|
|
+ tmp = item.strip().replace('\n','').split(' ')
|
|
|
+ vals = []
|
|
|
+ for t in tmp:
|
|
|
+ vals.append(t.split(':'))
|
|
|
+ for v in vals:
|
|
|
+ print(v)
|
|
|
+ if v[0] == 'byr':
|
|
|
+ val = int(v[1])
|
|
|
+ if val > 2002 or val < 1920:
|
|
|
+ print('byr invlid')
|
|
|
+ return False
|
|
|
+ if v[0] == 'iyr':
|
|
|
+ val = int(v[1])
|
|
|
+ if val > 2020 or val < 2010:
|
|
|
+ print('iyr invlid')
|
|
|
+ return False
|
|
|
+ if v[0] == 'eyr':
|
|
|
+ val = int(v[1])
|
|
|
+ if val > 2030 or val < 2020:
|
|
|
+ print('eyr invlid')
|
|
|
+ return False
|
|
|
+ if v[0] == 'hgt':
|
|
|
+ unit = v[1][-2:]
|
|
|
+ if unit not in ['cm','in']:
|
|
|
+ print('hgt wrong unit')
|
|
|
+ return False
|
|
|
+ val = int(v[1].replace(unit,''))
|
|
|
+ if unit == 'in':
|
|
|
+ if val > 76 or val < 59:
|
|
|
+ print('hgt out of range')
|
|
|
+ return False
|
|
|
+ if unit == 'cm':
|
|
|
+ if val > 193 or val < 150:
|
|
|
+ print('hgt out of range')
|
|
|
+ return False
|
|
|
+ if v[0] == 'hcl':
|
|
|
+ if len(v[1]) != 7:
|
|
|
+ print('hcl to short')
|
|
|
+ return False
|
|
|
+ if v[1][1] == '#':
|
|
|
+ print('hcl wrong format')
|
|
|
+ return False
|
|
|
+ for c in v[1].replace('#',''):
|
|
|
+ if c not in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']:
|
|
|
+ print('hcl unexpected char '+c)
|
|
|
+ return False
|
|
|
+ if v[0] == 'ecl':
|
|
|
+ if len(v[1]) != 3:
|
|
|
+ print('ecl to short')
|
|
|
+ return False
|
|
|
+ if v[1] not in ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth']:
|
|
|
+ print('ecl undefined value')
|
|
|
+ return False
|
|
|
+ if v[0] == 'pid':
|
|
|
+ if len(v[1]) != 9 or not v[1].isnumeric():
|
|
|
+ print('pid invaldi')
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
for i in items:
|
|
|
if 'byr' not in i:
|
|
|
continue
|
|
|
@@ -33,6 +93,7 @@ for i in items:
|
|
|
continue
|
|
|
if 'eyr' not in i:
|
|
|
continue
|
|
|
- valid += 1
|
|
|
+ if isvalid(i):
|
|
|
+ valid += 1
|
|
|
|
|
|
print(str(valid))
|