added year of 2023

This commit is contained in:
2025-06-05 22:45:07 +02:00
parent 15b6a0da55
commit 9632022b82
58 changed files with 3478 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
import java.io.File
fun main() {
var input = File("input.txt").readLines()
val seeds = input[0].split(":")[1].trim().split(" ")
var formattedInput = ""
val soilMap: HashMap<IntRange, IntRange> = HashMap()
val fertilizerMap: HashMap<IntRange, IntRange> = HashMap()
val waterMap: HashMap<IntRange, IntRange> = HashMap()
val lightMap: HashMap<IntRange, IntRange> = HashMap()
val temperatureMap: HashMap<IntRange, IntRange> = HashMap()
val humidityMap: HashMap<IntRange, IntRange> = HashMap()
val locationMap: HashMap<IntRange, IntRange> = HashMap()
input = input.drop(2)
input.forEach { line -> formattedInput += line.ifBlank { "#" }.plus(" ") }
val splitValue = formattedInput.split("#")
splitValue[0].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
soilMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
splitValue[1].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
fertilizerMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
splitValue[2].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
waterMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
splitValue[3].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
lightMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
splitValue[4].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
temperatureMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
splitValue[5].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
humidityMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
splitValue[6].split(": ").drop(1).forEach {
val numbers = it.trim().split(" ")
for (i in numbers.indices step 3) {
locationMap[numbers[i + 1].toInt()..<numbers[i + 1].toInt() + numbers[i + 2].toInt()] =
numbers[i].toInt()..<numbers[i].toInt() + numbers[i + 2].toInt()
}
}
var lowest = Int.MAX_VALUE
seeds.forEach { seed ->
val soil = 0
soilMap.keys.forEach {range ->
if (seed.toInt() in range){
soil =
}
}
}
}