Skip to content

Instantly share code, notes, and snippets.

@akamajoris
Created August 8, 2017 12:05
Show Gist options
  • Save akamajoris/5bd2639c74ba1539bc4e9a98ee08380a to your computer and use it in GitHub Desktop.
Save akamajoris/5bd2639c74ba1539bc4e9a98ee08380a to your computer and use it in GitHub Desktop.
package main
import "fmt"
func HeapPermutation(a []string, size int) {
if size == 1 {
fmt.Println(a)
}
for i := 0; i < size; i++ {
HeapPermutation(a, size-1)
if size%2 == 1 {
a[0], a[size-1] = a[size-1], a[0]
} else {
a[i], a[size-1] = a[size-1], a[i]
}
}
}
func main() {
a := []string{"a","b","c"}
HeapPermutation(a, len(a))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment