day 11 & day 12
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user