2015 / Day 11
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
import sys,time,re
|
import sys,time,re
|
||||||
from helpingFunctions import *
|
from helpingFunctions import *
|
||||||
|
import json
|
||||||
|
|
||||||
setSampleMode(False)
|
setSampleMode(False)
|
||||||
|
|
||||||
@@ -14,15 +15,29 @@ aocYear = identifyYear(sys.argv[0])
|
|||||||
path = getPath2Data(aocDay,aocYear)
|
path = getPath2Data(aocDay,aocYear)
|
||||||
filename = getFilename2Data(aocDay)
|
filename = getFilename2Data(aocDay)
|
||||||
|
|
||||||
|
def n(json):
|
||||||
|
if type(json) == int:
|
||||||
|
return json
|
||||||
|
if type(json) == list:
|
||||||
|
return sum([n(json) for json in json])
|
||||||
|
if type(json) != dict:
|
||||||
|
return 0
|
||||||
|
if 'red' in json.values():
|
||||||
|
return 0
|
||||||
|
return n(list(json.values()))
|
||||||
|
|
||||||
def taskA (data) -> int:
|
def taskA (data) -> int:
|
||||||
gameScoreA = 0
|
gameScoreA = 0
|
||||||
dataValue = re.findall(r'-[0-9]*||[0-9]*',data[0])
|
for dataLine in data:
|
||||||
for lineValue in dataValue:
|
dataValues = re.findall('(-?\d+)',dataLine)
|
||||||
gameScoreA = gameScoreA+ int(lineValue)
|
for dataValue in dataValues:
|
||||||
|
gameScoreA = gameScoreA+ int(dataValue)
|
||||||
return gameScoreA
|
return gameScoreA
|
||||||
|
|
||||||
def taskB (data) -> int:
|
def taskB (data) -> int:
|
||||||
gameScoreB = 0
|
gameScoreB = 0
|
||||||
|
for dataLine in data:
|
||||||
|
gameScoreB = gameScoreB+ n(json.loads(dataLine))
|
||||||
return gameScoreB
|
return gameScoreB
|
||||||
|
|
||||||
def task(task: int,data) -> int:
|
def task(task: int,data) -> int:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ def taskA (data) -> int:
|
|||||||
return gameScoreA
|
return gameScoreA
|
||||||
|
|
||||||
def taskB (data) -> int:
|
def taskB (data) -> int:
|
||||||
|
st=time.time()
|
||||||
gameScoreB = 0
|
gameScoreB = 0
|
||||||
return gameScoreB
|
return gameScoreB
|
||||||
|
|
||||||
@@ -39,9 +40,9 @@ def main():
|
|||||||
print ('please check file %s on path %s' % (filename, path))
|
print ('please check file %s on path %s' % (filename, path))
|
||||||
quit()
|
quit()
|
||||||
st=time.time()
|
st=time.time()
|
||||||
print ('Day '+aocDay+': Tasks 1: '+ str(task(1,data))+ ' executation time: ' + str(int((time.time()-st)*1000)) + 'ms')
|
print ('Day '+aocDay+': Tasks 1: '+ str(task(1,data)[0])+ ' executation time: ' + str(int((time.time()-st)*1000)) + 'ms')
|
||||||
st=time.time()
|
st=time.time()
|
||||||
print ('Day '+aocDay+': Tasks 2: '+ str(task(2,data))+ ' executation time: ' + str(int((time.time()-st)*1000)) + 'ms')
|
print ('Day '+aocDay+': Tasks 2: '+ str(task(2,data)[0])+ ' executation time: ' + str(int((time.time()-st)*1000)) + 'ms')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user