-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay8.py
41 lines (33 loc) · 931 Bytes
/
Day8.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
from PuzzleInput import ReadInput
pz_input = ReadInput(8).data
def part_a():
code_total = 0
for line in pz_input:
i = 0
while i < len(line):
if line[i] == "\"":
code_total += 1
i += 1
elif line[i] == "\\":
if line[i + 1] == "x":
code_total += 3
i += 4
else:
code_total += 1
i += 2
else:
i += 1
return code_total
def part_b():
# pz_input = ["\"\"", "\"abc\"", "\"aaa\\\"aaa\"", "\"\\x27\""]
total = 0
for line in pz_input:
if line == "":
continue
total += 2 # For new surrounding quotes
total += line.count("\"")
total += line.count("\\")
return total
if __name__ == "__main__":
print("Part A", part_a())
print("Part B", part_b())