diff options
author | mhsn <mail@mhsn.net> | 2024-12-11 09:28:32 +0000 |
---|---|---|
committer | mhsn <mail@mhsn.net> | 2024-12-11 09:28:32 +0000 |
commit | 8ea562f5d1d76cf9c9e2ef80560e72c32104c3fb (patch) | |
tree | dafac7daca2e6500bb28f1548ebe4a63e72b32d1 | |
parent | 84723ce9e2457fa8aa0bb2790a8c13242e88ec7e (diff) | |
download | aoc-8ea562f5d1d76cf9c9e2ef80560e72c32104c3fb.tar.gz aoc-8ea562f5d1d76cf9c9e2ef80560e72c32104c3fb.zip |
2024-11 python p1,p2
-rw-r--r-- | 2024/11/python/main.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/2024/11/python/main.py b/2024/11/python/main.py new file mode 100644 index 0000000..445809a --- /dev/null +++ b/2024/11/python/main.py @@ -0,0 +1,28 @@ +from fileinput import input +from functools import cache +from math import floor, log + +stones = [int(x) for x in input().readline().split()] + + +@cache +def blink(s, n): + if n == 0: + return 1 + + if s == 0: + return blink(1, n - 1) + + digits = floor(log(s, 10) + 1e-6) + 1 + if digits % 2 == 0: + left, right = divmod(s, 10 ** (digits // 2)) + return blink(left, n - 1) + blink(right, n - 1) + + return blink(s * 2024, n - 1) + + +silver = sum(blink(s, 25) for s in stones) +gold = sum(blink(s, 75) for s in stones) + +print("silver:", silver) +print("gold:", gold) |