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.
There is also a command-line tool for invoking these operations on a list of strings.
For library usage, please see the documentation at pkg.go.dev.
Installing the command-line tool:
go install github.com/bobg/combo/cmd/combo@latestUsage:
combo perm [ARG ARG ...]
combo comb N [ARG ARG ...]
combo rcomb N [ARG ARG ...]The first argument is the operation to run:
perm for permutations;
comb for combinations;
and rcomb for combinations-with-replacement.
The comb and rcomb subcommands require a numeric argument, N,
the number of strings to choose in each combination.
The input is specified as additional arguments on the command line. If no such arguments are supplied, then the input is read from standard input, one line per string.
Examples:
$ combo perm 1 2 3
1 2 3
2 1 3
3 1 2
1 3 2
2 3 1
3 2 1$ combo comb 2 a b c
a b
a c
b c$ combo rcomb 2 a b c
a a
a b
a c
b b
b c
c c