diff --git a/count_parentheses.py b/count_parentheses.py index 7dc6524..54a181e 100644 --- a/count_parentheses.py +++ b/count_parentheses.py @@ -7,9 +7,25 @@ PARENS = list("()[]{}<>") SMILEYS = [":D", "D:"] -def main(): +def print_a_bunch(what: str, how_much: int, all: bool) -> None: + while how_much > 0: + print(what * min(80, how_much)) + if not all: + break + how_much -= 80 + + +def balance(count: Counter[str], a: str, b: str, all: bool) -> None: + if count[a] > count[b]: + print_a_bunch(b, count[a] - count[b], all) + if count[b] > count[a]: + print_a_bunch(a, count[b] - count[a], all) + + +def main() -> None: parser = ArgumentParser() parser.add_argument("path", type=Path) + parser.add_argument("--all", "-a", action="store_true") args = parser.parse_args() count = Counter[str]() @@ -26,6 +42,11 @@ def main(): for smiley in SMILEYS: print(f"{smiley} - {count[smiley]:6}") + balance(count, "(", ")", args.all) + balance(count, "[", "]", args.all) + balance(count, "{", "}", args.all) + balance(count, "<", ">", args.all) + if __name__ == "__main__": main()