From a2e29d58d0cfd752c4495f25e129d680f9e7d5ef Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 7 Jul 2025 00:57:10 +0200 Subject: [PATCH] Count parenthesis parity in a room --- count_parentheses.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 count_parentheses.py diff --git a/count_parentheses.py b/count_parentheses.py new file mode 100644 index 0000000..54cac13 --- /dev/null +++ b/count_parentheses.py @@ -0,0 +1,24 @@ +import json +from argparse import ArgumentParser +from pathlib import Path +from typing import Counter + + +def main(): + parser = ArgumentParser() + parser.add_argument("path", type=Path) + args = parser.parse_args() + + chars = Counter[str]() + with open(args.path) as f: + print("Reading lines") + for line in f: + content = json.loads(line)["content"] + chars += Counter(content) + + for c in "()[]{}<>": + print(f"{c} - {chars[c]:6}") + + +if __name__ == "__main__": + main()