This commit is contained in:
Daniel Weber 2024-12-11 08:22:47 -05:00
parent 464f462b89
commit 3e6f031781

View File

@ -4,7 +4,9 @@ import os
sys.path.insert(1, os.path.abspath('../../')) sys.path.insert(1, os.path.abspath('../../'))
from python_tools.aoc_utils import * from python_tools.aoc_utils import *
G = {} import collections as C
G = C.defaultdict(lambda: 0)
def blink_rocks(r): def blink_rocks(r):
if r == 0: if r == 0:
@ -15,47 +17,30 @@ def blink_rocks(r):
else: else:
return [r*2024] return [r*2024]
def blink_rocksp2(r):
if r not in G: def solve(stones, num):
x = [r] G.clear()
for i in range(3): for i in stones:
G[i] += 1
for i in range(num):
nx = [] nx = []
for j in x: g = G.copy()
nx.extend(blink_rocks(j)) G.clear()
x = nx for j in g:
G[r] = x result = blink_rocks(j)
return G[r] for k in result:
G[k]+=g[j]
def part_one(stones): ans = 0
x = stones for i in G:
for i in range(25): ans += G[i]
nx = [] print(f"Stones after {num} blinks: {ans}")
for j in x:
nx.extend(blink_rocks(j))
x = nx
print("Part One: ", len(x))
STONES = set()
def part_two(stones):
x = stones
for i in range(25):
print(i)
nx = []
for j in x:
nx.extend(blink_rocks(j))
for i in nx:
STONES.add(i)
x = nx
print("Len_stones: ", len(STONES))
print("Part Two: ", len(x))
def main(): def main():
f = open("input.txt", "r") f = open("input.txt", "r")
contents = list(map(int, f.read().strip().split())) contents = list(map(int, f.read().strip().split()))
part_one(contents) solve(contents, 25)
part_two(contents) solve(contents, 75)
if __name__ == "__main__": if __name__ == "__main__":
main() main()