Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Combinations ¶
Combinations produces a sequence containing all n-length combinations of distinct elements from s.
If s is [1 2 3] and n is 2, this function will produce:
[1 2] [1 3] [2 3]
Example ¶
package main
import (
"fmt"
"github.com/bobg/combo"
)
func main() {
slice := []int{1, 2, 3, 4}
combs := combo.Combinations(slice, 2)
for c := range combs {
fmt.Println(c)
}
}
Output: [1 2] [1 3] [1 4] [2 3] [2 4] [3 4]
func CombinationsWithReplacement ¶
CombinationsWithReplacement produces a sequence containing all n-length combinations of possibly repeated elements from s.
If s is [1 2 3] and n is 2, this function will produce:
[1 1] [1 2] [1 3] [2 2] [2 3] [3 3]
Example ¶
package main
import (
"fmt"
"github.com/bobg/combo"
)
func main() {
slice := []int{1, 2, 3}
rcombs := combo.CombinationsWithReplacement(slice, 2)
for c := range rcombs {
fmt.Println(c)
}
}
Output: [1 1] [1 2] [1 3] [2 2] [2 3] [3 3]
func Permutations ¶
Permutations produces a sequence containing all permutations of s. It uses Heap's Algorithm. See https://en.wikipedia.org/wiki/Heap%27s_algorithm.
If s is [1 2 3], this function will produce:
[1 2 3] [2 1 3] [3 1 2] [1 3 2] [2 3 1] [3 2 1]
Example ¶
package main
import (
"fmt"
"github.com/bobg/combo"
)
func main() {
slice := []int{1, 2, 3}
perms := combo.Permutations(slice)
for p := range perms {
fmt.Println(p)
}
}
Output: [1 2 3] [2 1 3] [3 1 2] [1 3 2] [2 3 1] [3 2 1]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.