Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeongoon/go-combinations
https://github.com/jeongoon/go-combinations
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jeongoon/go-combinations
- Owner: jeongoon
- License: osl-3.0
- Created: 2022-04-06T05:28:09.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-07T12:32:37.000Z (almost 3 years ago)
- Last Synced: 2024-11-05T11:16:22.447Z (2 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-combinations
`go-combinations` is a simple module to create combinations of unsigned integer,
which you can use as indexes on your array (or slice)## Given M, Select N
- SomeIndexes
create all possible combinations **except** none.- AllIndexes
create all possible combinations where you pick certain number of candidates
which is actually calling SomeIndexes with all range of selection (1..N)## Install
```sh
go get github.com/jeongoon/go-combinations```
## Usage```go
package mainimport "fmt"
import combo "github.com/jeongoon/go-combinations"
/* ^^^^^ is an alias for this module */func main() {
someAlphas := []string{ "A", "B", "C", "D", "E" }
fmt.Printf( "given elements are:\n%v\n", someAlphas )for _, cb := range combo.SomeIndexes(len(someAlphas), 3) {
fmt.Printf( "[%v %v %v]\n",
someAlphas[cb[0]], someAlphas[cb[1]], someAlphas[cb[2]] )
}
}
```