# Golang program to print all Permutations of a given string

A permutation, is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation. Let's take an example of "ABCD" and write a program to generate all possible permutation and combinations of string in Golang.

### Example

```
``````
package main
import (
"fmt"
)
func join(ins []rune, c rune) (result []string) {
for i := 0; i <= len(ins); i++ {
result = append(result, string(ins[:i])+string(c)+string(ins[i:]))
}
return
}
func permutations(testStr string) []string {
var n func(testStr []rune, p []string) []string
n = func(testStr []rune, p []string) []string{
if len(testStr) == 0 {
return p
}else {
result := []string{}
for _, e := range p {
result = append(result, join([]rune(e), testStr[0])...)
}
return n(testStr[1:], result)
}
}
output := []rune(testStr)
return n(output[1:], []string{string(output[0])})
}
func main() {
d := permutations("ABCD")
fmt.Print(d)
}
```

##### Most Helpful This Week

Undefined <variable/function> error in Golang
Avoid Unintended Variable Shadowing in Golang
GO Program to Find Factorial of a Number
GO supports the standard arithmetic operators: (Addition, Subtraction, Multiplication, Division,Remainder)
Print inverted full pyramid using star
How to slice elements in Golang?
Use Field Tags in the Definition of Struct Type
GO Program to Swap Number Without Using Temporary Variables
Go program to reading plain text files
Golang program for implementation of Bubble Sort