Skip to content

A Golang implementation of Heap's algorithm to generate all possible permutations

License

Notifications You must be signed in to change notification settings

dbyio/heappermutations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]]

About

A Golang implementation of Heap's algorithm to generate all possible permutations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages