day 11 & day 12

This commit is contained in:
2024-12-14 21:41:56 +01:00
parent fa4e8f7a58
commit 441dac30b7
10 changed files with 418 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
import sys,time
from helpingFunctions import *
from functools import lru_cache
setSampleMode(False)
@@ -13,13 +14,50 @@ aocYear = identifyYear(sys.argv[0])
path = getPath2Data(aocDay,aocYear)
filename = getFilename2Data(aocDay)
lookup={}
@lru_cache(maxsize=None)
def laserStone(stone):
if stone == 0:
return [1]
elif len(str(stone))%2 == 0:
l = len(str(stone))
stone=str(stone)
j = int(l/2)
return [int(stone[:j]),int(stone[j:])]
else:
return [int(stone)*2024]
def taskA (data) -> int:
gameScoreA = 0
stoneRow = [int(stone) for stone in data[0].split(' ')]
for i in range(25):
print ("Loop:" + str(i) + " = " + str(len(stoneRow)))
listStone=[]
for stone in stoneRow:
newStone= laserStone(stone)
listStone = listStone + newStone
stoneRow = listStone
gameScoreA = len(stoneRow)
return gameScoreA
def taskB (data) -> int:
gameScoreB = 0
stoneRow = [int(stone) for stone in data[0].split(' ')]
for i in range(75):
print ("Loop:" + str(i) + " = " + str(len(stoneRow)))
listStone=[]
for stone in stoneRow:
try:
newStone = lookup[stone]
except:
newStone= laserStone(stone)
lookup[stone] = newStone
listStone = listStone + newStone
stoneRow = listStone
gameScoreB = len(stoneRow)
return gameScoreB
def task(task: int,data) -> int: