added year of 2023
This commit is contained in:
70
2023/02/Kotlin/src/main/kotlin/Main.kt
Normal file
70
2023/02/Kotlin/src/main/kotlin/Main.kt
Normal 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")
|
||||
}
|
||||
8
2023/02/Kotlin/src/test/kotlin/TestMain.kt
Normal file
8
2023/02/Kotlin/src/test/kotlin/TestMain.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class TestMain {
|
||||
@Test fun test() {
|
||||
assertEquals(true, true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user