Skip to content

Instantly share code, notes, and snippets.

@trajber
Created November 7, 2014 22:01
Show Gist options
  • Save trajber/4157cfbe695c4e46b5a2 to your computer and use it in GitHub Desktop.
Save trajber/4157cfbe695c4e46b5a2 to your computer and use it in GitHub Desktop.
Permutation of a string in Golang
package main
import "fmt"
func perm(str []rune, i int) {
if i == len(str) {
fmt.Println(string(str))
} else {
for j := i; j < len(str); j++ {
str[i], str[j] = str[j], str[i]
perm(str, i+1)
str[i], str[j] = str[j], str[i]
}
}
}
func main() {
perm([]rune("abcde"), 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment