11-1 ok, but 11-2-fail
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
44
11/11-2-ki.py
Normal file
44
11/11-2-ki.py
Normal 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')
|
||||
Reference in New Issue
Block a user