2015: d08: ex2: add solution
This commit is contained in:
parent
797b104850
commit
40f9ff8ae8
1 changed files with 23 additions and 0 deletions
23
2015/d08/ex2/ex2.py
Executable file
23
2015/d08/ex2/ex2.py
Executable 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue