@@ -42,25 +42,21 @@ humidity-to-location map:
4242fun main () {
4343 // println("Sample Input A: ${solutionA(inputSample)}")
4444 // println("Sample Input B: ${solutionB(inputSample)}")
45- // println("Part A: ${solutionA(puzzleInputFromFile("src/main/kotlin/com/rox/adventofcode/y2023/Day5.input"))}")
46- println (" Part B: ${solutionB(puzzleInputFromFile(" src/main/kotlin/com/rox/adventofcode/y2023/Day5.input" ))} " )
45+ println (" Part A: ${solutionA(puzzleInputFromFile(" src/main/kotlin/com/rox/adventofcode/y2023/Day5.input" ))} " )
46+ // println("Part B: ${solutionB(puzzleInputFromFile("src/main/kotlin/com/rox/adventofcode/y2023/Day5.input"))}")
4747}
4848
4949data class CategoryConversion (val from : String , val to : String , val mappings : MutableList <RangeAndOffset >){
5050 fun getMappingFor (value : Long ): Long {
5151 val mappedValue = mappings.firstOrNull { m -> value in m.range }
5252 if (mappedValue != null ) return (value + mappedValue.offset) else return value
5353 }
54-
55- fun g (range : LongRange ){
56-
57- }
5854}
5955
6056data class RangeAndOffset (val range : LongRange , val offset : Long )
6157
6258/* *
63- * Answer: ???
59+ * Answer: 218513636
6460 */
6561private fun solutionA (input : String ): Any {
6662 val rows = input.split(' \n ' )
@@ -97,7 +93,7 @@ private fun solutionA(input: String): Any {
9793
9894/* *
9995 *
100- * Answer: ???
96+ * Answer: 81956384
10197 */
10298private fun solutionB (input : String ): Any {
10399 val rows = input.split(' \n ' )
@@ -125,12 +121,10 @@ private fun solutionB(input: String): Any {
125121
126122 var nearestSeed = Long .MAX_VALUE
127123 for (seedRange in rangesOfSeedsToPlant) {
128- println (" Range: ${seedRange.first} -${seedRange.last} of ${rangesOfSeedsToPlant.size} " )
129124 for (seed in seedRange) {
130125 var seedProgress = seed
131126 for (stage in listOf (" seed" , " soil" , " fertilizer" , " water" , " light" , " temperature" , " humidity" )) {
132- seedProgress = categories[stage]?.getMappingFor(seedProgress)!!
133- // println("$stage: $seedProgress")
127+ seedProgress = categories[stage]?.getMappingFor(seedProgress)!!
134128 }
135129 nearestSeed = min(nearestSeed, seedProgress)
136130 }
0 commit comments