https://kotlinlang.org logo
#announcements
Title
# announcements
o

orangy

03/06/2016, 2:49 PM
Copy code
private fun josephus(size: Int, step: Int): Int {
    val circle = (0..size - 1).toMutableList()
    var index = step % circle.size
    while (circle.size > 1) {
        circle.removeAt(index)
        index = (index + step - 1) % circle.size
    }
    return circle[0]
}
👍 1