Skip to content

Commit

Permalink
[2024/11] p1 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 11, 2024
1 parent 8a45499 commit 3909bad
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Binary file added .aoc_tiles/tiles/2024/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions 2024/11/example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
125 17
39 changes: 39 additions & 0 deletions 2024/11/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from GhostyUtils import aoc
import math


def num_digits(value: int) -> int:
return int(math.log10(value)) + 1


def blink(stones: list[int]) -> list[int]:
new_stones = []
for i, stone in enumerate(stones):
if stone == 0:
new_stones.append(1)
elif num_digits(stone) % 2 == 0:
digits = num_digits(stone)
um = 10 ** (digits//2)
l_stone = stone // um
r_stone = stone - (l_stone * um)
new_stones += [l_stone, r_stone]
else:
new_stones.append(stone * 2024)

return new_stones


def main():
stones = [int(stone) for stone in aoc.read().split()]
if aoc.args.verbose:
print(stones)

for _ in range(25):
stones = blink(stones)
if aoc.args.verbose:
print(stones)
print(f"p1: {len(stones)}")


if __name__ == "__main__":
main()
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code

<!-- AOC TILES BEGIN -->
<h1 align="center">
Advent of Code - 181/470
Advent of Code - 182/472
</h1>
<h1 align="center">
2024 - 20 ⭐ - Python
2024 - 21 ⭐ - Python
</h1>
<a href="2024/1/script.py">
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
Expand Down Expand Up @@ -38,6 +38,9 @@ My solutions to the yearly Advents of Code
<a href="2024/10/script.py">
<img src=".aoc_tiles/tiles/2024/10.png" width="161px">
</a>
<a href="2024/11/script.py">
<img src=".aoc_tiles/tiles/2024/11.png" width="161px">
</a>
<h1 align="center">
2023 - 47 ⭐ - Python
</h1>
Expand Down

0 comments on commit 3909bad

Please sign in to comment.