powerset

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: MIT Imports: 1 Imported by: 1

README

powerset

Generic powerset algorithm for go

Install

go get github.com/chanced/powerset

Usage

package main

func main() {

    fmt.Println(powerset.Compute([]string{"a", "b", "c"}))
    // output: [[] [a] [b] [a b] [c] [a c] [b c] [a b c]]

    fmt.Println(powerset.Compute([]int{1, 2, 3}))
    // output: [[] [1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]
}

Contributions

Contributions of any kind are always welcome. If there's a problem or there is a way to improve this algorithm, please feel free to open an issue or pull request.

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compute

func Compute[T any](set []T) [][]T

Compute returns the powerset of the given set.

Example
package main

import (
	"fmt"

	"github.com/chanced/powerset"
)

func main() {
	fmt.Println(powerset.Compute([]string{"a", "b", "c"}))

	fmt.Println(powerset.Compute([]int{1, 2, 3}))
}
Output:

[[] [a] [b] [a b] [c] [a c] [b c] [a b c]]
[[] [1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]

Types

This section is empty.

Jump to

Keyboard shortcuts

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