11-1 ok, but 11-2-fail

This commit is contained in:
2024-12-11 13:04:50 +01:00
parent 9e9eac67b6
commit 85e37d4d91
3 changed files with 47 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ if __name__ == "__main__":
puzzle = puzzle_input.split() puzzle = puzzle_input.split()
puzzle = str_list_to_int_list(puzzle) puzzle = str_list_to_int_list(puzzle)
for x in range(x_blink): for x in range(x_blink):
print(x+1)
puzzle = blink(puzzle) puzzle = blink(puzzle)
#print(puzzle) #print(puzzle)
print(f'input: {puzzle_input} and {x_blink} blinks -> {len(puzzle)} stones') print(f'input: {puzzle_input} and {x_blink} blinks -> {len(puzzle)} stones')

View File

@@ -30,7 +30,8 @@ def blink(int_array:np.ndarray) -> np.ndarray:
@njit() @njit()
def do_x_blinks(x:int, arr:np.ndarray) -> int: def do_x_blinks(x:int, arr:np.ndarray) -> int:
for _ in range(x): for i in range(x):
print(i+1)
arr = blink(arr) arr = blink(arr)
return len(arr) return len(arr)

44
11/11-2-ki.py Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from time import time
from collections import Counter
# Puzzle-Input
input_stones = [112, 1110, 163902, 0, 7656027, 83039, 9, 74]
def transform_stone(stone):
if stone == 0:
return [1]
elif len(str(stone)) % 2 == 0:
mid = len(str(stone)) // 2
left = int(str(stone)[:mid])
right = int(str(stone)[mid:])
return [left, right]
else:
return [stone * 2024]
def blink(stones, times):
stone_counts = Counter(stones)
for i in range(1, times + 1):
new_stone_counts = Counter()
for stone, count in stone_counts.items():
for new_stone in transform_stone(stone):
new_stone_counts[new_stone] += count
stone_counts = new_stone_counts
total_stones = sum(stone_counts.values())
print(f"Blinzeln {i}: {total_stones} Steine")
return total_stones
start = time()
# Teil 1: 25 Mal blinzeln
result_part1 = blink(input_stones, 25)
print(f"Nach 25 Mal Blinzeln: {result_part1} Steine")
# Teil 2: 75 Mal blinzeln
result_part2 = blink(input_stones, 75)
print(f"Nach 75 Mal Blinzeln: {result_part2} Steine")
print(f'\nLaufzeit: {time()-start:.2f} s')