File tree Expand file tree Collapse file tree 1 file changed +3
-14
lines changed
src/main/kotlin/io/dmitrijs/aoc2022 Expand file tree Collapse file tree 1 file changed +3
-14
lines changed Original file line number Diff line number Diff line change 11package io.dmitrijs.aoc2022
22
3- import kotlin.math.absoluteValue
4- import kotlin.math.sign
5-
63class Day20 (private val input : List <Long >) {
74 fun puzzle1 () = decipher()
85
@@ -25,17 +22,9 @@ class Day20(private val input: List<Long>) {
2522 private fun List<Number>.zeroIndex () = indexOfFirst { it.value == 0L }
2623
2724 private fun MutableList<Number>.mix (order : Int ) {
28- val index = indexOfFirst { it.order == order }
29- val value = this [index].value
30-
31- val rawIndex = (index + value.sign * (value.absoluteValue % lastIndex)).toInt()
32- val newIndex = when {
33- rawIndex <= 0 -> size - (rawIndex.absoluteValue + 1 )
34- rawIndex >= size -> rawIndex % size + 1
35- else -> rawIndex
36- }
37-
38- add(newIndex, removeAt(index))
25+ val oldIndex = indexOfFirst { it.order == order }
26+ val newIndex = (oldIndex + this [oldIndex].value).mod(size - 1 )
27+ add(newIndex, removeAt(oldIndex))
3928 }
4029
4130 private fun <T > List<T>.nth (num : Int ) = this [num % size]
You can’t perform that action at this time.
0 commit comments