Skip to content

Commit

Permalink
2024 day 11 parts 1
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Dec 13, 2024
1 parent b30f29e commit 24934fb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- 2021 - ★★★★★ ★★★★★ ★★★★★ ★★★
- 2022 - ★★★★★ ★★★★★ ★★★★★ ★☆
- 2023 - ★★★★★ ★★★★★ ★★★★★ ★★★☆
- 2024 - ★★★★★ ★★★★★
- 2024 - ★★★★★ ★★★★★

## How to use

Expand Down
26 changes: 26 additions & 0 deletions src/year2024/day11a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""2024 - Day 11 Part 1: Plutonian Pebbles"""


def solve(task: str) -> int:
stones = [int(x) for x in task.split()]

for _ in range(25):
new_stones: list[int] = []

for stone in stones:
if stone == 0:
new_stones.append(1)
elif (len_stone := len(str_stone := str(stone))) % 2 == 0:
middle = len_stone // 2

left = str_stone[:middle]
right = str_stone[middle:]

new_stones.append(int(left))
new_stones.append(int(right))
else:
new_stones.append(stone * 2024)

stones = new_stones

return len(stones)
8 changes: 8 additions & 0 deletions tests/src/year2024/test_day11a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""2024 - Day 11 Part 1: Plutonian Pebbles"""

from src.year2024.day11a import solve


def test_solve():
task = "125 17"
assert solve(task) == 55312

0 comments on commit 24934fb

Please sign in to comment.