From d1653a9aec67b39edf2b804a2dc82684952a5676 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 11 Dec 2024 09:16:06 -0500 Subject: [PATCH] 2024: d11: ex1: add solution --- 2024/d11/ex1/ex1.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 2024/d11/ex1/ex1.py diff --git a/2024/d11/ex1/ex1.py b/2024/d11/ex1/ex1.py new file mode 100755 index 0000000..8360f5d --- /dev/null +++ b/2024/d11/ex1/ex1.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import sys + + +def solve(input: str) -> int: + def parse(input: str) -> list[int]: + return [int(n) for n in input.split()] + + def blink(stones: list[int]) -> list[int]: + res: list[int] = [] + for n in stones: + if n == 0: + res.append(1) + elif len(str(n)) % 2 == 0: + s = str(n) + lhs, rhs = s[: len(s) // 2], s[len(s) // 2 :] + res.extend((int(lhs), int(rhs))) + else: + res.append(n * 2024) + return res + + stones = parse(input) + for _ in range(25): + stones = blink(stones) + return len(stones) + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()