Skip to content

Instantly share code, notes, and snippets.

@voddan
Last active June 4, 2016 14:35
Show Gist options
  • Save voddan/e224905a73f2afa894c7ee32de3a31fc to your computer and use it in GitHub Desktop.
Save voddan/e224905a73f2afa894c7ee32de3a31fc to your computer and use it in GitHub Desktop.
import java.util.*
class Permutations(N: Int) : IntCombinations(N) {
override val state = mutableListOf<Ring>()
init {
for(i in N downTo 1) {
state += Ring(i)
}
}
override fun state(): List<Int> {
val items = (0..size - 1).toCollection(LinkedList())
return state.map {ring -> items.removeAt(ring.state())}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment