diff --git a/11/11-1.py b/11/11-1.py index e69f704..b69b057 100644 --- a/11/11-1.py +++ b/11/11-1.py @@ -38,6 +38,7 @@ if __name__ == "__main__": puzzle = puzzle_input.split() puzzle = str_list_to_int_list(puzzle) for x in range(x_blink): + print(x+1) puzzle = blink(puzzle) #print(puzzle) print(f'input: {puzzle_input} and {x_blink} blinks -> {len(puzzle)} stones') diff --git a/11/11-2-fail.py b/11/11-2-fail.py index 8ab2b58..75dc631 100644 --- a/11/11-2-fail.py +++ b/11/11-2-fail.py @@ -30,7 +30,8 @@ def blink(int_array:np.ndarray) -> np.ndarray: @njit() 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) return len(arr) diff --git a/11/11-2-ki.py b/11/11-2-ki.py new file mode 100644 index 0000000..8aeec9b --- /dev/null +++ b/11/11-2-ki.py @@ -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') \ No newline at end of file