Skip to content

Instantly share code, notes, and snippets.

@ekeitho
Created July 12, 2018 03:40
Show Gist options
  • Save ekeitho/111c5c8f08a575d9eac62d687880cb79 to your computer and use it in GitHub Desktop.
Save ekeitho/111c5c8f08a575d9eac62d687880cb79 to your computer and use it in GitHub Desktop.
Make all combinations of size k
fun comboOfSizeK(word: String, r: Int): List<String> {
val list = arrayListOf<String>()
fun comobs(word: String, created: String, start: Int, end: Int, sizeOfCombo: Int) {
if (created.length == sizeOfCombo) {
list.add(created)
return
}
if (start > end) {
return
}
for(i in start..end) {
comobs(word,created + word[i], i+1, end, sizeOfCombo)
}
}
comobs(word, "", 0, word.length - 1, r)
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment