Skip to content

Instantly share code, notes, and snippets.

@andrewgazelka
Created February 28, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgazelka/63b8665928ae68dd00bdaed40161e9c2 to your computer and use it in GitHub Desktop.
Save andrewgazelka/63b8665928ae68dd00bdaed40161e9c2 to your computer and use it in GitHub Desktop.
private fun distinctLoopHelper(depth: Int, range: IntRange, on: Int, counter: IntArray) = sequence {
for (i in range) {
counter[on] = i
if (depth == 0) {
yield(counter)
}
else yieldAll(distinctLoopHelper(depth - 1, i..range.endInclusive, on + 1, counter))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment