Compare commits
No commits in common. "bf55c705754eae73a1863aca6a9a7d4f06ca6df0" and "acc32964f54c867f3dcc4f2c410c9d5dc2047fe5" have entirely different histories.
bf55c70575
...
acc32964f5
|
@ -1,35 +0,0 @@
|
|||
#!/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()
|
|
@ -1 +0,0 @@
|
|||
0 7 6618216 26481 885 42 202642 8791
|
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def parse(input: str) -> Counter[int]:
|
||||
return Counter(int(n) for n in input.split())
|
||||
|
||||
def blink(stones: Counter[int]) -> Counter[int]:
|
||||
res: Counter[int] = Counter()
|
||||
for n, count in stones.items():
|
||||
if n == 0:
|
||||
res[1] += count
|
||||
elif len(str(n)) % 2 == 0:
|
||||
s = str(n)
|
||||
lhs, rhs = s[: len(s) // 2], s[len(s) // 2 :]
|
||||
res[int(lhs)] += count
|
||||
res[int(rhs)] += count
|
||||
else:
|
||||
res[n * 2024] += count
|
||||
return res
|
||||
|
||||
stones = parse(input)
|
||||
for _ in range(75):
|
||||
stones = blink(stones)
|
||||
return sum(stones.values())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1 +0,0 @@
|
|||
0 7 6618216 26481 885 42 202642 8791
|
Loading…
Reference in a new issue