LastExceed
06/19/2020, 11:05 AMval 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?