From 771b7f7d251a4636097dd8e91da300ddd189676c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 1 Dec 2023 12:13:28 +0000 Subject: [PATCH] 2023: d01: ex1: add solution --- 2023/d01/ex1/ex1.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 2023/d01/ex1/ex1.py diff --git a/2023/d01/ex1/ex1.py b/2023/d01/ex1/ex1.py new file mode 100755 index 0000000..52b6f8d --- /dev/null +++ b/2023/d01/ex1/ex1.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import sys + + +def solve(input: list[str]) -> int: + def value(line: str) -> int: + digits = [int(c) for c in line if c.isdigit()] + return digits[0] * 10 + digits[-1] + + return sum(value(line) for line in input) + + +def main() -> None: + input = sys.stdin.read().splitlines() + print(solve(input)) + + +if __name__ == "__main__": + main()