From 2637d63c4ec776c7f50d31af8a062d482ce4a528 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 1 Dec 2022 09:57:27 +0100 Subject: [PATCH] 2022: d01: ex2: add solution --- 2022/d01/ex2/ex2.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 2022/d01/ex2/ex2.py diff --git a/2022/d01/ex2/ex2.py b/2022/d01/ex2/ex2.py new file mode 100755 index 0000000..55591e4 --- /dev/null +++ b/2022/d01/ex2/ex2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import sys + + +def solve(input: list[list[int]]) -> int: + totals: list[int] = sorted(map(sum, input), reverse=True) + return sum(totals[:3]) + + +def main() -> None: + input = [ + [int(line) for line in group.split("\n") if line] + for group in sys.stdin.read().split("\n\n") + if group + ] + print(solve(input)) + + +if __name__ == "__main__": + main()