Kotlin provide a way to deal with value ranges, so you might be able to simply create and manipulate ranges
Control if a value belong or not to a range of elements.
Iteration over ranges
Reverse iteration over ranges
Iterating over ranges ... step by step
Range with exclusion
The #1 tech hiring platform