combo

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 3 Imported by: 0

README

Combo - combinatorial operations for Go

Go Reference Go Report Card Tests Coverage Status

This is combo, a library of combinatorial operations for Go. Given a slice, it can compute its permutations, its n-element combinations, and its n-element combinations-with-replacement.

Please see the documentation at pkg.go.dev.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Combinations

func Combinations[T any, S ~[]T](s S, n int) iter.Seq[S]

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]

func CombinationsWithReplacement

func CombinationsWithReplacement[T any, S ~[]T](s S, n int) iter.Seq[S]

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]

func Permutations

func Permutations[T any, S ~[]T](s S) iter.Seq[S]

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]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL