Skip to content

Commit

Permalink
Solution day 11 from 2024 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkopec87 authored Dec 11, 2024
1 parent 74525eb commit 649a1b9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/2024/11/2024_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from collections import Counter

from src.utils.data import load_data
from src.utils.submission import submit_or_print


def main(debug: bool) -> None:
input_data = load_data(debug)

stone_counter = parse_input(input_data)

result_part1 = sum(blink(stone_counter, 25).values())
result_part2 = sum(blink(stone_counter, 75).values())

submit_or_print(result_part1, result_part2, debug)


def parse_input(input_data: str) -> Counter[int]:
return Counter([int(n) for n in input_data.split(" ")])


def blink(initial_state: Counter[int], blinks: int) -> Counter[int]:
current_state = Counter(initial_state)
for _ in range(blinks):
next_state = Counter(current_state)

for number, count in current_state.items():
next_state[number] -= count
if number == 0:
next_state[1] += count
elif len(str(number)) % 2 == 0:
s = str(number)
split_point = len(s) // 2
first = int(s[:split_point])
second = int(s[split_point:])
next_state[first] += count
next_state[second] += count
else:
next_state[2024 * number] += count

current_state = next_state

return current_state


if __name__ == "__main__":
debug_mode = True
# debug_mode = False
main(debug_mode)
1 change: 1 addition & 0 deletions src/2024/11/sample_input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
131 1200

0 comments on commit 649a1b9

Please sign in to comment.