2015: d08: ex2: add solution

This commit is contained in:
Bruno BELANYI 2025-05-21 02:35:42 +01:00
parent 797b104850
commit 40f9ff8ae8

23
2015/d08/ex2/ex2.py Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env python
import collections
import sys
def solve(input: str) -> int:
def quote_len(raw: str) -> int:
characters = collections.Counter(raw)
# The `+ 2` is for the surrounding quotes
return characters.total() + characters['"'] + characters["\\"] + 2
strings = input.splitlines()
return sum(quote_len(raw) - len(raw) for raw in strings)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()