Skip to content

Commit

Permalink
2024 Day 11 Part 2 Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
pcorliss committed Dec 12, 2024
1 parent 1a1f8e3 commit 0ec7c90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
26 changes: 22 additions & 4 deletions 2024/11/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,32 @@ def blink(stones):

return out

STONE_CACHE = {}

def recursive_blink(stones, iterations):
if iterations == 0:
return len(stones)

sum = 0
for stone in stones:
if (stone, iterations) in STONE_CACHE:
sum += STONE_CACHE[(stone, iterations)]
continue

stone_count = recursive_blink(blink([stone]), iterations - 1)
sum += stone_count
# print(f"stone: {stone} iterations: {iterations} count: {stone_count}")
STONE_CACHE[(stone, iterations)] = stone_count

return sum

def part1(input_text):
stones = parse(input_text)
for _ in range(25):
stones = blink(stones)
return len(stones)
return recursive_blink(stones, 25)

def part2(input_text):
return 0
stones = parse(input_text)
return recursive_blink(stones, 75)

if __name__ == "__main__":
with open(__file__.rsplit('/', 1)[0] + "/input.txt", 'r') as file:
Expand Down
13 changes: 13 additions & 0 deletions 2024/11/daily_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def test_blink(parsed_data, times, expected):

assert d == expected

@pytest.mark.parametrize("times, expected", [
(1, 3),
(2, 4),
(3, 5),
(4, 9),
(5, 13),
(6, 22),
])
def test_recursive_blink(parsed_data, times, expected):
count = recursive_blink(parsed_data, times)

assert count == expected

def test_part1(sample_data):
assert part1(sample_data) == 55312

Expand Down

0 comments on commit 0ec7c90

Please sign in to comment.