Created
November 7, 2014 22:01
-
-
Save trajber/4157cfbe695c4e46b5a2 to your computer and use it in GitHub Desktop.
Permutation of a string in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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