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:
x = [r]
for i in range(3):
nx = []
for j in x:
nx.extend(blink_rocks(j))
x = nx
G[r] = x
return G[r]
def part_one(stones): def solve(stones, num):
x = stones G.clear()
for i in range(25): 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:
print("Part One: ", len(x)) result = blink_rocks(j)
for k in result:
STONES = set() G[k]+=g[j]
ans = 0
def part_two(stones): for i in G:
x = stones ans += G[i]
for i in range(25): print(f"Stones after {num} blinks: {ans}")
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()