added year of 2023

This commit is contained in:
2025-06-05 22:45:07 +02:00
parent e8e76885ae
commit 66007c5389
58 changed files with 3478 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
import java.io.File
fun main(args: Array<String>) {
//part1()
part2()
}
fun part2(){
val data = File("input.txt").readLines()
var sum = 0;
data.forEach { game ->
var maxBlue = 0
var maxRed = 0
var maxGreen = 0
val temp1 = game.split(":")
val gameId = temp1[0].split(" ")[1].toInt()
val rounds = temp1[1].trim().split("; ")
//println(rounds)
rounds.forEach { round ->
val temp2 = round.split(", ")
//println(temp2)
temp2.forEach { blocks ->
//println(blocks)
val count = blocks.split(" ")[0].toInt()
val colour = blocks.split(" ")[1]
when (colour){
"red" -> if (count > maxRed) maxRed = count
"blue" -> if (count > maxBlue) maxBlue = count
"green" -> if (count > maxGreen) maxGreen = count
else -> Unit
}
}
}
sum += maxRed * maxGreen * maxBlue
}
println("Result: $sum")
}
fun part1(){
val data = File("input.txt").readLines()
var sum = 0;
data.forEach { game ->
var maxBlue = 0
var maxRed = 0
var maxGreen = 0
val temp1 = game.split(":")
val gameId = temp1[0].split(" ")[1].toInt()
val rounds = temp1[1].trim().split("; ")
//println(rounds)
rounds.forEach { round ->
val temp2 = round.split(", ")
//println(temp2)
temp2.forEach { blocks ->
//println(blocks)
val count = blocks.split(" ")[0].toInt()
val colour = blocks.split(" ")[1]
when (colour){
"red" -> if (count > maxRed) maxRed = count
"blue" -> if (count > maxBlue) maxBlue = count
"green" -> if (count > maxGreen) maxGreen = count
else -> Unit
}
}
}
if (maxRed <= 12 && maxBlue <= 14 && maxGreen <= 13){
sum += gameId
}
}
println("Result: $sum")
}

View File

@@ -0,0 +1,8 @@
import kotlin.test.Test
import kotlin.test.assertEquals
internal class TestMain {
@Test fun test() {
assertEquals(true, true)
}
}