-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpartOne.py
More file actions
37 lines (27 loc) · 840 Bytes
/
partOne.py
File metadata and controls
37 lines (27 loc) · 840 Bytes
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
import re
from common import *
def partOne(instr: str) -> int:
input_list = parse(instr)
test_cases = [
# Regex to match expression, bool if can be skipped
[r"byr:([^ ]+)", False],
[r"iyr:([^ ]+)", False],
[r"eyr:([^ ]+)", False],
[r"hgt:([^ ]+)", False],
[r"hcl:([^ ]+)", False],
[r"ecl:([^ ]+)", False],
[r"pid:([^ ]+)", False],
[r"cid:([^ ]+)", True],
]
valid_passports = 0
for passport in input_list:
results = []
for tc in test_cases:
results.append([re.search(tc[0], passport) is not None, tc[1]])
valid = True
for r in results:
if not (r[0] or r[1]):
valid = False
break
valid_passports += 1 if valid else 0
return valid_passports