63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
# with open('./2020/04.test') as input:
|
|
with open('./2020/04.input') as input:
|
|
input_data = input.read()
|
|
|
|
input_list = input_data.split("\n\n")
|
|
|
|
working_list = []
|
|
for one_input in input_list:
|
|
one_worker = {}
|
|
one_input = one_input.replace('\n', ' ')
|
|
attribute_list = one_input.split(' ')
|
|
for one_attribute in attribute_list:
|
|
attributes = one_attribute.split(":")
|
|
one_worker[attributes[0]] = attributes[1]
|
|
working_list.append(one_worker)
|
|
|
|
target_list = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']
|
|
valid_count = 0
|
|
for one_item in working_list:
|
|
if all(element in one_item.keys() for element in target_list):
|
|
valid_count += 1
|
|
print(valid_count)
|
|
|
|
valid_count = 0
|
|
for one_item in working_list:
|
|
test_check = 0
|
|
test_str = ""
|
|
if all(element in one_item.keys() for element in target_list):
|
|
test_check += 1
|
|
test_str = test_str + "keys|"
|
|
else:
|
|
continue
|
|
if int(one_item['byr']) >= 1920 and int(one_item['byr']) <= 2002:
|
|
test_check += 1
|
|
test_str = test_str + "birth_year|"
|
|
if int(one_item['iyr']) >= 2010 and int(one_item['iyr']) <= 2020:
|
|
test_check += 1
|
|
test_str = test_str + "issue_year|"
|
|
if int(one_item['eyr']) >= 2020 and int(one_item['eyr']) <= 2030:
|
|
test_check += 1
|
|
test_str = test_str + "expire_year|"
|
|
|
|
print(one_item['hgt'][-2])
|
|
if (one_item['hgt'][-2] == 'cm' and int(one_item['hgt'][:-2]) >= 150 and int(one_item['hgt'][:-2]) <= 193) or (one_item['hgt'][-2] == 'in' and int(one_item['hgt'][:-2]) >= 50 and int(one_item['hgt'][:-2]) <= 76):
|
|
test_check += 1
|
|
test_str = test_str + "height|"
|
|
print(one_item['hcl'], len(one_item['hcl']))
|
|
if len(one_item['hcl']) == 7:
|
|
test_check += 1
|
|
test_str = test_str + "hair|"
|
|
if one_item['ecl'] in ['amb', 'blu', 'brn', 'gry', 'grn','hzl', 'oth']:
|
|
test_check += 1
|
|
test_str = test_str + "eye|"
|
|
if len(one_item['pid']) == 9:
|
|
test_check += 1
|
|
test_str = test_str + "passport|"
|
|
if test_check == 7:
|
|
valid_count += 1
|
|
print(test_check)
|
|
print(test_str)
|
|
print(one_item)
|
|
|
|
print(valid_count) |