🎄Advent of Code - Day 2 part 2

This commit is contained in:
Denis-Cosmin Nutiu 2023-12-02 12:27:50 +02:00
parent c58688c25c
commit 9feaac9deb
2 changed files with 18 additions and 16 deletions

View file

@ -59,24 +59,26 @@ class CubeConundrum : Puzzle {
What is the sum of the power of these sets? What is the sum of the power of these sets?
*/ */
val games = getGameList(); val games = getGameList();
val sum = games.map {
var gamePower = 0 var gamePower = 0
val gameMaxConstraints = mapOf( var minimumPerGame = mutableMapOf(
"red" to 12, "red" to 0,
"green" to 13, "green" to 0,
"blue" to 14 "blue" to 0
) )
games.forEach {
it.gameData?.forEach { gameData -> it.gameData?.forEach { gameData ->
val cubes = gameData.split(",") val cubes = gameData.split(",")
cubes.forEach cubeForEach@{ cubeSet -> cubes.forEach cubeForEach@{ cubeSet ->
val cubeData = cubeSet.trim().split(" ") val cubeData = cubeSet.trim().split(" ")
println() minimumPerGame[cubeData[1]] =
Math.max(minimumPerGame[cubeData[1]]!!, cubeData[0].toInt())
} }
} }
gamePower = 0 gamePower = minimumPerGame["red"]!! * minimumPerGame["green"]!! * minimumPerGame["blue"]!!
}
println("The sum of the game ids is $gamePower.") gamePower
}.sum()
println("The sum of the game power is $sum.")
} }
} }

View file

@ -2,6 +2,6 @@ import AdventOfCode2023.day2.CubeConundrum
fun main(args: Array<String>) { fun main(args: Array<String>) {
val t = CubeConundrum() val t = CubeConundrum()
t.partOne() // t.partOne()
// t.partTwo() t.partTwo()
} }