Skip to content

Instantly share code, notes, and snippets.

@hugows
Created May 5, 2015 14:13
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 hugows/fd992d775980a4870201 to your computer and use it in GitHub Desktop.
Save hugows/fd992d775980a4870201 to your computer and use it in GitHub Desktop.
// [[a b] [c d]] -> [[a c] [a d] [b c] [b d]]
func combinations(path []int, sets [][]int, acc *[][]int) {
if len(sets) == 0 {
*acc = append(*acc, path)
} else {
for _, el := range sets[0] {
path := append(path, el)
np := make([]int, len(path))
copy(np, path)
combinations(np, sets[1:], acc)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment