Skip to content

Commit ebb79db

Browse files
committed
use shifting start index instead of sublists
1 parent 3f92385 commit ebb79db

File tree

1 file changed

+2
-3
lines changed
  • src/main/kotlin/me/peckb/aoc/_2025/calendar/day03

1 file changed

+2
-3
lines changed

src/main/kotlin/me/peckb/aoc/_2025/calendar/day03/Day03.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ class Day03 @Inject constructor(
1717
private fun maxJoltage(
1818
batteryArray: List<Long>,
1919
startIndex: Int = 0,
20-
endIndex: Int = batteryArray.size - 1,
2120
numToEnable: Int,
2221
) : Long {
23-
val subListIndices = startIndex .. (endIndex - (numToEnable - 1))
22+
val subListIndices = startIndex .. ((batteryArray.size - 1) - (numToEnable - 1))
2423

2524
val indexOfLargest = subListIndices.maxBy { i -> batteryArray[i] }
2625
val largestStartValue = batteryArray[indexOfLargest]
@@ -30,7 +29,7 @@ class Day03 @Inject constructor(
3029

3130
// if we have more batteries to flip - find the indices for those batteries and send down the new arrays
3231
val possibleStartIndices = subListIndices.filter { i -> batteryArray[i] == largestStartValue }
33-
val maxSubJoltage = possibleStartIndices.maxOf { i -> maxJoltage(batteryArray.drop(i + 1), numToEnable = numToEnable - 1) }
32+
val maxSubJoltage = possibleStartIndices.maxOf { i -> maxJoltage(batteryArray, startIndex = i + 1, numToEnable = numToEnable - 1) }
3433

3534
// then add it to our value and return!
3635
return "$largestStartValue$maxSubJoltage".toLong()

0 commit comments

Comments
 (0)