advent-of-code/2015/08/part1.py

26 lines
557 B
Python
Raw Normal View History

2021-12-01 11:07:21 +01:00
with open("input") as f:
lines = [n.strip() for n in f.readlines()]
solution = 0
for line in lines:
char_count = 0
i = 1
while i < len(line) - 1:
char = line[i]
if char == "\\":
next_char = line[i + 1]
if next_char in ["\\", '"']:
i += 1
elif next_char in ["x"]:
i += 3
char_count += 1
i += 1
literal_count = len(line)
print(f"{line}: {literal_count=}, {char_count=}")
solution += literal_count - char_count
print(solution)