day 2024.08
This commit is contained in:
@@ -13,9 +13,56 @@ aocYear = identifyYear(sys.argv[0])
|
||||
|
||||
path = getPath2Data(aocDay,aocYear)
|
||||
filename = getFilename2Data(aocDay)
|
||||
|
||||
def identifyAntennes(data):
|
||||
posAntennes={}
|
||||
maxY = len(data)
|
||||
maxX = len(data[0])
|
||||
for posY in range(maxY):
|
||||
for posX in range(maxX):
|
||||
dataValue = data[posY][posX]
|
||||
if dataValue != '.':
|
||||
try:
|
||||
posAntennes[dataValue].append((posX,posY))
|
||||
except:
|
||||
posAntennes[dataValue] = [(posX,posY)]
|
||||
return maxY,maxX,posAntennes
|
||||
|
||||
def isinGrid(pos,maxPos):
|
||||
return 0 <= pos[0] < maxPos[0] and 0 <= pos[1] < maxPos[1]
|
||||
|
||||
def calcAntiNodes(posAntA, posAntB,maxPos):
|
||||
AX = posAntA[0]
|
||||
BX = posAntB[0]
|
||||
AY = posAntA[1]
|
||||
BY = posAntB[1]
|
||||
CX = AX + (AX-BX)
|
||||
CY = AY + (AY-BY)
|
||||
|
||||
if isinGrid ((CX,CY),maxPos):
|
||||
return (CX,CY)
|
||||
return (-1,-1)
|
||||
|
||||
def findAntiNodes(maxY,maxX,posAntennes):
|
||||
maxPos = (maxX,maxY)
|
||||
posAntiNodes=[]
|
||||
posAntennesList = posAntennes.keys()
|
||||
for antenne in posAntennesList:
|
||||
for posAntA in posAntennes[antenne]:
|
||||
for posAntB in posAntennes[antenne]:
|
||||
if posAntA != posAntB:
|
||||
antiNode = calcAntiNodes(posAntA,posAntB,maxPos)
|
||||
if antiNode != (-1,-1):
|
||||
posAntiNodes.append(antiNode)
|
||||
return posAntiNodes
|
||||
|
||||
def taskA (data) -> int:
|
||||
gameScoreA = 0
|
||||
maxY,maxX,posAntennes = identifyAntennes(data)
|
||||
antiNodes = findAntiNodes(maxY,maxX,posAntennes)
|
||||
antiNodes = list(set(antiNodes))
|
||||
gameScoreA = len(antiNodes)
|
||||
print (data)
|
||||
return gameScoreA
|
||||
|
||||
def taskB (data) -> int:
|
||||
|
||||
Reference in New Issue
Block a user