Horner's rule for polynomial evaluation Any better ways to implement 'inverseIndices'? Please give me feedback regarding good coding conventions. 

fun main(arg: Array&lt;String&gt;) {
    //− 19 + 7 x − 4 x 2 + 6 x 3
    val coefficients = arrayListOf&lt;Int&gt;(-19, 7, -4, 6)
    val x = 3
    var result: Int = 0
    for (i in coefficients.inverseIndices) {
        result = (result*x) + coefficients[i]
    }
    println(result)
}



val ArrayList&lt;Int&gt;.inverseIndices: IntProgression
    get() = (size -1).downTo(0)
I suppose you can use .reversed() or  .asReversed() to reverse the list of coefficients and iterate over it, without working with the indices:

coefficients.asReversed().forEach {
    result = (result * x) + it
}


Also, you can use the functional idiom of fold/reduce, and replace iteration with folding the list (here, .foldRight(...) is used to fold the collection from its end):

val x = 3
val result = coefficients.foldRight(0) { it, acc -&gt; it + acc * x }