Update 2015 / 07
This commit is contained in:
@@ -6,30 +6,79 @@
|
|||||||
import sys,time
|
import sys,time
|
||||||
from helpingFunctions import *
|
from helpingFunctions import *
|
||||||
|
|
||||||
setSampleMode(True)
|
setSampleMode(False)
|
||||||
|
|
||||||
aocDay = identifyDay(sys.argv[0])
|
aocDay = identifyDay(sys.argv[0])
|
||||||
aocYear = identifyYear(sys.argv[0])
|
aocYear = identifyYear(sys.argv[0])
|
||||||
|
|
||||||
path = getPath2Data(aocDay,aocYear)
|
path = getPath2Data(aocDay,aocYear)
|
||||||
filename = getFilename2Data(aocDay)
|
filename = getFilename2Data(aocDay)
|
||||||
|
|
||||||
|
def calculateWire(defWire,calculationSteps,valueWire):
|
||||||
|
retVal = 0
|
||||||
|
try:
|
||||||
|
retVal = int(defWire)
|
||||||
|
return retVal,valueWire
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if defWire not in valueWire:
|
||||||
|
calculationStep = calculationSteps[defWire]
|
||||||
|
if len(calculationStep) == 1:
|
||||||
|
calculateValueA, valueWire = calculateWire(calculationStep[0],calculationSteps,valueWire)
|
||||||
|
retVal = calculateValueA
|
||||||
|
else:
|
||||||
|
calc = calculationStep[-2]
|
||||||
|
if calc == 'AND':
|
||||||
|
calculateValueA, valueWire = calculateWire(calculationStep[0],calculationSteps,valueWire)
|
||||||
|
calculateValueB, valueWire = calculateWire(calculationStep[2],calculationSteps,valueWire)
|
||||||
|
retVal = calculateValueA & calculateValueB
|
||||||
|
elif calc == 'OR':
|
||||||
|
calculateValueA, valueWire = calculateWire(calculationStep[0],calculationSteps,valueWire)
|
||||||
|
calculateValueB, valueWire = calculateWire(calculationStep[2],calculationSteps,valueWire)
|
||||||
|
retVal = calculateValueA | calculateValueB
|
||||||
|
elif calc == 'NOT':
|
||||||
|
calculateValueA, valueWire = calculateWire(calculationStep[1],calculationSteps,valueWire)
|
||||||
|
retVal = 0xffff - calculateValueA
|
||||||
|
elif calc == 'RSHIFT':
|
||||||
|
calculateValueA, valueWire = calculateWire(calculationStep[0],calculationSteps,valueWire)
|
||||||
|
calculateValueB, valueWire = calculateWire(calculationStep[2],calculationSteps,valueWire)
|
||||||
|
retVal = calculateValueA >> calculateValueB
|
||||||
|
elif calc == 'LSHIFT':
|
||||||
|
calculateValueA, valueWire = calculateWire(calculationStep[0],calculationSteps,valueWire)
|
||||||
|
calculateValueB, valueWire = calculateWire(calculationStep[2],calculationSteps,valueWire)
|
||||||
|
retVal = calculateValueA << calculateValueB
|
||||||
|
valueWire[defWire] = retVal
|
||||||
|
return valueWire[defWire],valueWire
|
||||||
|
|
||||||
|
def createCalcSteps(data):
|
||||||
|
calculationSteps={}
|
||||||
|
for dataRow in data:
|
||||||
|
(commandString, targetWire) = dataRow.split('->')
|
||||||
|
calculationSteps[targetWire.strip()]= commandString.strip().split(' ')
|
||||||
|
return calculationSteps
|
||||||
|
|
||||||
def taskA (data) -> int:
|
def taskA (data) -> int:
|
||||||
gameScoreA = 0
|
gameScoreA = 0
|
||||||
for dataRow in data:
|
calculationSteps=createCalcSteps(data)
|
||||||
|
gameScoreA,valueWire = calculateWire('a',calculationSteps,{})
|
||||||
return gameScoreA
|
return gameScoreA
|
||||||
|
|
||||||
def taskB (data) -> int:
|
def taskB (data,valueA) -> int:
|
||||||
gameScoreB = 0
|
gameScoreB = 0
|
||||||
|
calculationSteps=createCalcSteps(data)
|
||||||
|
gameScoreB,valueWire = calculateWire('a',calculationSteps,{'b':valueA})
|
||||||
return gameScoreB
|
return gameScoreB
|
||||||
|
|
||||||
def task(task: int,data) -> int:
|
def task(task: int,data) -> int:
|
||||||
|
global scoreA
|
||||||
|
global scoreB
|
||||||
score=0
|
score=0
|
||||||
if task == 1:
|
if task == 1:
|
||||||
score = taskA(data)
|
score = taskA(data)
|
||||||
|
scoreA=score
|
||||||
elif task == 2:
|
elif task == 2:
|
||||||
score = taskB(data)
|
score = taskB(data,scoreA)
|
||||||
return score
|
return score
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user