what the fuck is this code... should use some regex tbh

This commit is contained in:
Peter 2020-12-04 14:15:50 +08:00
parent a0f6b8594f
commit ef5adffb49
2 changed files with 72 additions and 0 deletions

26
4/a.py Normal file
View File

@ -0,0 +1,26 @@
lines = open('input').read().splitlines()
arr = []
arr_ = []
for line in lines:
_ = line.replace(':',' ').split(' ')
if _[0] == '':
arr.append(arr_)
print("A")
arr_ = []
else:
arr_ = arr_ + _
arr.append(arr_)
a = 0
for line in arr:
print(line)
c = 0
for key in line:
if key in ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']:
c += 1
if c >= 7:
a += 1
print(c)
print(a)

46
4/b.py Normal file
View File

@ -0,0 +1,46 @@
lines = open('input').read().splitlines()
arr = []
arr_ = []
for line in lines:
_ = line.split(' ')
if _[0] == '':
arr.append(arr_)
arr_ = []
else:
arr_ = arr_ + _
arr.append(arr_)
def v(v, k, l, u):
if v[0] == k and l <= int(v[1]) <= u:
return 1
else:
return 0
A = 0
for line in arr:
c = 0
print(line)
for field in line:
a = field.split(':')
# if a[0] in ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']:
# c += 1
c += v(a, 'byr', 1920, 2002)
c += v(a, 'iyr', 2010, 2020)
c += v(a, 'eyr', 2020, 2030)
if a[0] == 'hgt':
if a[1][-2]+a[1][-1] == 'cm' and 150 <= int(a[1].replace('cm', '')) <= 193:
c += 1
elif a[1][-2]+a[1][-1] == 'in' and 59 <= int(a[1].replace('in', '')) <= 76:
c += 1
elif a[0] == 'hcl' and a[1][0] == "#" and len(a[1]) == 7:
c += 1
elif a[0] == 'ecl' and a[1] in ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth']:
c += 1
elif a[0] == 'pid' and len(a[1]) == 9:
c += 1
print(c)
if c == 7:
A += 1
print(A)