You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
466 B
Python
22 lines
466 B
Python
3 years ago
|
with open("input") as f:
|
||
|
lines = [n.strip() for n in f.readlines()]
|
||
|
|
||
|
solution = 0
|
||
|
|
||
|
for line in lines:
|
||
|
literal_count = len(line)
|
||
|
|
||
|
char_count = 2 # surrounding double quotes: '"'
|
||
|
i = 0
|
||
|
while i < len(line):
|
||
|
char = line[i]
|
||
|
if char in ['"', "\\", ""]:
|
||
|
char_count += 1
|
||
|
char_count += 1
|
||
|
i += 1
|
||
|
|
||
|
print(f"{line}: {literal_count=}, {char_count=}")
|
||
|
solution += char_count - literal_count
|
||
|
|
||
|
print(solution)
|