update day 9 + 10 Yea<r 2015

This commit is contained in:
2024-11-10 21:43:08 +01:00
parent e0be09b6d3
commit d39f5c9b4c
6 changed files with 79 additions and 3 deletions

View File

@@ -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

View File

@@ -0,0 +1,3 @@
London to Dublin = 464
London to Belfast = 518
Dublin to Belfast = 141

View File

@@ -0,0 +1 @@
1113222113

View File

@@ -0,0 +1 @@
111221

View File

@@ -4,6 +4,8 @@
# Developer : David Bandeira
import sys,time
from itertools import permutations
from helpingFunctions import *
setSampleMode(False)
@@ -14,14 +16,43 @@ 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:

View File

@@ -5,6 +5,7 @@
import sys,time
from helpingFunctions import *
from itertools import groupby
setSampleMode(False)
@@ -14,12 +15,23 @@ 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: