From ef5adffb493a425b2b770aba5d83b48e54db4683 Mon Sep 17 00:00:00 2001 From: npc-strider Date: Fri, 4 Dec 2020 14:15:50 +0800 Subject: [PATCH] what the fuck is this code... should use some regex tbh --- 4/a.py | 26 ++++++++++++++++++++++++++ 4/b.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 4/a.py create mode 100644 4/b.py diff --git a/4/a.py b/4/a.py new file mode 100644 index 0000000..071acee --- /dev/null +++ b/4/a.py @@ -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) \ No newline at end of file diff --git a/4/b.py b/4/b.py new file mode 100644 index 0000000..c4da9bd --- /dev/null +++ b/4/b.py @@ -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) \ No newline at end of file