I am doing challenges on hackerrank to improve my ...
# codereview
l
I am doing challenges on hackerrank to improve my code style. I just solved this one: https://www.hackerrank.com/challenges/2d-array/problem with this submission:
Copy code
val offsets = setOf(
        0 to 0,
        1 to 0,
        2 to 0,
        1 to 1,
        0 to 2,
        1 to 2,
        2 to 2
    )

    val results = mutableListOf<Int>()
    
    repeat(4) { x ->
        repeat(4) { y ->
            val sum = offsets.fold(0) { acc, pair ->
                acc + arr[y + pair.second][x + pair.first]
            }
            results.add(sum)
        }
    }

    results.sort()
    return results.last()
It works, however I feel like it could be better. the usage of a
mutableList
and nested
repeat()
in particular seem smelly to me. Is there a more functional approach for this?