From 95f307a0d65c6452655032f89556c878155f69e5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 1 Dec 2025 21:08:18 +0000 Subject: [PATCH] 2025: d01: ex1: add solution --- 2025/d01/ex1/ex1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 2025/d01/ex1/ex1.py diff --git a/2025/d01/ex1/ex1.py b/2025/d01/ex1/ex1.py new file mode 100755 index 0000000..d9c2bfa --- /dev/null +++ b/2025/d01/ex1/ex1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import itertools +import sys + + +def solve(input: list[str]) -> int: + def parse_turn(input: str) -> int: + direction = input[0] + clicks = int(input[1:]) + return clicks * (1 if direction == "R" else -1) + + def parse(input: list[str]) -> list[int]: + return [parse_turn(turn) for turn in input] + + turns = parse(input) + positions = itertools.accumulate(turns, initial=50) + return sum(pos % 100 == 0 for pos in positions) + + +def main() -> None: + input = sys.stdin.read().splitlines() + print(solve(input)) + + +if __name__ == "__main__": + main()