-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_04a.py
More file actions
29 lines (25 loc) · 740 Bytes
/
day_04a.py
File metadata and controls
29 lines (25 loc) · 740 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
#!/usr/bin/env python3
def main():
f = open("../input/day_04_input")
key_fields = {"byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"}
n_valid = 0
n_fields = 0
n_lines = 0
for line in f:
line = line.strip().replace("\n", "").replace("\r", "")
if len(line) == 0:
if n_fields == len(key_fields):
n_valid += 1
n_fields = 0
continue
fields = line.split()
for field in fields:
split_field = field.split(":")
if split_field[0].strip() in key_fields:
n_fields += 1
if n_fields == len(key_fields):
n_valid += 1
print(n_valid)
return n_valid
if __name__ == "__main__":
main()