Skip to content

Latest commit

 

History

History
23 lines (13 loc) · 705 Bytes

File metadata and controls

23 lines (13 loc) · 705 Bytes

The heappermutations package provides a Golang implementation of B. R. Heap's algorithm to generate all possible permutations of typed-datasets.

Based on https://en.wikipedia.org/wiki/Heap's_algorithm

Available functions

func Permute[T any]([]T) [][]T

Permute returns all permutations of a typed slice.

Usage

import ( "github.com/dbyio/heappermutations" )

sInts := []int{1, 2, 3}
pInts := heappermutations.Permute(sInts)		// [[1 2 3] [2 1 3] [3 1 2] [1 3 2] [2 3 1] [3 2 1]]

sStrings := []string{"a", "b", "c"}
pStrings := heappermutations.Permute(sStrings)	// [[a b c] [b a c] [c a b] [a c b] [b c a] [c b a]]