advent_of_code/2024/day11/main.py

63 lines
1.2 KiB
Python
Raw Normal View History

2024-12-11 07:02:57 -05:00
from contextlib import contextmanager
import sys
import os
sys.path.insert(1, os.path.abspath('../../'))
from python_tools.aoc_utils import *
G = {}
def blink_rocks(r):
if r == 0:
return [1]
elif len(str(r)) % 2 == 0:
l = int(len(str(r)) / 2)
return [int(str(r)[:l]), int(str(r)[l:])]
else:
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):
x = stones
for i in range(25):
nx = []
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():
f = open("input.txt", "r")
contents = list(map(int, f.read().strip().split()))
part_one(contents)
part_two(contents)
if __name__ == "__main__":
main()