From 40f9ff8ae8d3326217a1a823eb6d41c922e934a6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 21 May 2025 02:35:42 +0100 Subject: [PATCH] 2015: d08: ex2: add solution --- 2015/d08/ex2/ex2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 2015/d08/ex2/ex2.py diff --git a/2015/d08/ex2/ex2.py b/2015/d08/ex2/ex2.py new file mode 100755 index 0000000..247844b --- /dev/null +++ b/2015/d08/ex2/ex2.py @@ -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()