Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day11(s, *, part2=False):
- @functools.cache
- def length(e: str, num_steps: int) -> int:
- if num_steps == 0:
- return 1
- if e == '0':
- return length('1', num_steps - 1)
- if len(e) % 2 == 0:
- e1, e2 = e[: len(e) // 2], (e[len(e) // 2 :].lstrip('0') or '0')
- return length(e1, num_steps - 1) + length(e2, num_steps - 1)
- return length(str(int(e) * 2024), num_steps - 1)
- return sum(length(e, (25, 75)[part2]) for e in s.split())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement