2015 / Day 11
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import sys,time,re
|
||||
from helpingFunctions import *
|
||||
import json
|
||||
|
||||
setSampleMode(False)
|
||||
|
||||
@@ -13,16 +14,30 @@ aocYear = identifyYear(sys.argv[0])
|
||||
|
||||
path = getPath2Data(aocDay,aocYear)
|
||||
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:
|
||||
gameScoreA = 0
|
||||
dataValue = re.findall(r'-[0-9]*||[0-9]*',data[0])
|
||||
for lineValue in dataValue:
|
||||
gameScoreA = gameScoreA+ int(lineValue)
|
||||
for dataLine in data:
|
||||
dataValues = re.findall('(-?\d+)',dataLine)
|
||||
for dataValue in dataValues:
|
||||
gameScoreA = gameScoreA+ int(dataValue)
|
||||
return gameScoreA
|
||||
|
||||
def taskB (data) -> int:
|
||||
gameScoreB = 0
|
||||
for dataLine in data:
|
||||
gameScoreB = gameScoreB+ n(json.loads(dataLine))
|
||||
return gameScoreB
|
||||
|
||||
def task(task: int,data) -> int:
|
||||
|
||||
Reference in New Issue
Block a user