diff --git a/2015/data/day09/input.day09 b/2015/data/day09/input.day09 index e69de29..ed251ee 100644 --- a/2015/data/day09/input.day09 +++ b/2015/data/day09/input.day09 @@ -0,0 +1,28 @@ +AlphaCentauri to Snowdin = 66 +AlphaCentauri to Tambi = 28 +AlphaCentauri to Faerun = 60 +AlphaCentauri to Norrath = 34 +AlphaCentauri to Straylight = 34 +AlphaCentauri to Tristram = 3 +AlphaCentauri to Arbre = 108 +Snowdin to Tambi = 22 +Snowdin to Faerun = 12 +Snowdin to Norrath = 91 +Snowdin to Straylight = 121 +Snowdin to Tristram = 111 +Snowdin to Arbre = 71 +Tambi to Faerun = 39 +Tambi to Norrath = 113 +Tambi to Straylight = 130 +Tambi to Tristram = 35 +Tambi to Arbre = 40 +Faerun to Norrath = 63 +Faerun to Straylight = 21 +Faerun to Tristram = 57 +Faerun to Arbre = 83 +Norrath to Straylight = 9 +Norrath to Tristram = 50 +Norrath to Arbre = 60 +Straylight to Tristram = 27 +Straylight to Arbre = 81 +Tristram to Arbre = 90 \ No newline at end of file diff --git a/2015/data/day09/sample.day09 b/2015/data/day09/sample.day09 index e69de29..d8224f9 100644 --- a/2015/data/day09/sample.day09 +++ b/2015/data/day09/sample.day09 @@ -0,0 +1,3 @@ +London to Dublin = 464 +London to Belfast = 518 +Dublin to Belfast = 141 \ No newline at end of file diff --git a/2015/data/day10/input.day10 b/2015/data/day10/input.day10 index e69de29..1742d89 100644 --- a/2015/data/day10/input.day10 +++ b/2015/data/day10/input.day10 @@ -0,0 +1 @@ +1113222113 \ No newline at end of file diff --git a/2015/data/day10/sample.day10 b/2015/data/day10/sample.day10 index e69de29..1324ce7 100644 --- a/2015/data/day10/sample.day10 +++ b/2015/data/day10/sample.day10 @@ -0,0 +1 @@ +111221 \ No newline at end of file diff --git a/2015/day09.py b/2015/day09.py index e57c061..9606cc4 100644 --- a/2015/day09.py +++ b/2015/day09.py @@ -4,6 +4,8 @@ # Developer : David Bandeira import sys,time +from itertools import permutations + from helpingFunctions import * setSampleMode(False) @@ -13,15 +15,44 @@ aocYear = identifyYear(sys.argv[0]) path = getPath2Data(aocDay,aocYear) filename = getFilename2Data(aocDay) - + +def calcDistances(data): + trips={} + locations=[] + for dataRow in data: + trip,distance = dataRow.split(' = ') + locationA,locationB = trip.split(' to ') + locations.append(locationA) + locations.append(locationB) + locations = list(set(locations)) + trips[(locationA.strip(),locationB.strip())]=int(distance.strip()) + trips[(locationB.strip(),locationA.strip())]=int(distance.strip()) + allTrips = list(permutations(locations)) + distanceTrips={} + for run in allTrips: + allDistance=0 + for i in range(len(run)-1): + allDistance += trips[(run[i],run[i+1])] + distanceTrips[run]=allDistance + return distanceTrips + def taskA (data) -> int: + global distanceTrips gameScoreA = 0 + tripSearchDistance = 0 + distanceTrips = calcDistances(data) + for tripList,tripDistance in distanceTrips.items(): + if tripSearchDistance == 0 or tripSearchDistance > tripDistance: tripSearchDistance = tripDistance + gameScoreA=tripSearchDistance return gameScoreA def taskB (data) -> int: gameScoreB = 0 + tripSearchDistance = 0 + for tripList,tripDistance in distanceTrips.items(): + if tripSearchDistance == 0 or tripSearchDistance < tripDistance: tripSearchDistance = tripDistance + gameScoreB=tripSearchDistance return gameScoreB - def task(task: int,data) -> int: score=0 if task == 1: diff --git a/2015/day10.py b/2015/day10.py index e57c061..356c370 100644 --- a/2015/day10.py +++ b/2015/day10.py @@ -5,6 +5,7 @@ import sys,time from helpingFunctions import * +from itertools import groupby setSampleMode(False) @@ -13,13 +14,24 @@ aocYear = identifyYear(sys.argv[0]) path = getPath2Data(aocDay,aocYear) filename = getFilename2Data(aocDay) - + +def calcData(data): + return ''.join(str(len(list(count))) + digit for digit, count in groupby(data)) + def taskA (data) -> int: gameScoreA = 0 + data = data[0] + for turn in range(40): + data = calcData(data) + gameScoreA = len(data) return gameScoreA def taskB (data) -> int: gameScoreB = 0 + data = data[0] + for turn in range(50): + data = calcData(data) + gameScoreB = len(data) return gameScoreB def task(task: int,data) -> int: