-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2020P4.py
51 lines (41 loc) · 1.72 KB
/
2020P4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import re
with open(r"AoC2020_Day4_input.txt", 'r') as file:
data = [[{k.split(':')[0]:k.split(':')[1]} for k in list(i.split())]
for i in file.read().split('\n\n')]
Data = []
for i in data:
p = dict()
for k in i:
p.update(k)
Data.append(p)
"""
with open(r"input.txt", 'r') as file:
smalldata = [[{k.split(':')[0]:k.split(':')[1]} for k in list(i.split())]
for i in file.read().split('\n\n')]
SmallData = []
for i in smalldata:
p = dict()
for k in i:
p.update(k)
SmallData.append(p) """
def checkValidOld(passport):
if (len(passport) < 7) or ((len(passport) == 7) and ("cid" in passport)):
return False
return True
def checkValidNew(passport):
if (len(passport) < 7) or ((len(passport) == 7) and ("cid" in passport)):
return False
try:
if (1920 <= int(passport["byr"]) <= 2002) and (2010 <= int(passport["iyr"]) <= 2020) and (2020 <= int(passport["eyr"]) <= 2030) and ((150 <= int(passport['hgt'][:-2]) <= 193) if (passport["hgt"][-2:] == "cm") else (59 <= int(passport['hgt'][:-2]) <= 76)) and ((len(passport['hcl']) == 7) and bool(re.match(r'#[0-9a-f]{6}', passport['hcl']))) and (passport['ecl'] in ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth']) and ((len(passport['pid']) == 9) and bool(re.match(r'[0-9]{9}', passport['pid']))):
return True
except:
print(passport)
return 0
return False
# A fuckin patchwork , should revisit this , one of the Passport has a fckin empty 'ecl' value hence was giving error for a long time , but anyways <(_ _)>
cnt = 0
for i in Data:
if checkValidNew(i):
cnt += 1
print(cnt)
# ANSWER = 156