added year of 2023
This commit is contained in:
76
2023/05/Kotlin/src/Main.kt
Normal file
76
2023/05/Kotlin/src/Main.kt
Normal 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 =
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user