what about https://play.golang.org/p/TbZ-fbhUCb ?
the code don't create goroutine. thus you don't have to care about troubles with managing goroutine. 2016년 7월 13일 수요일 오전 6시 36분 15초 UTC+9, The MrU 님의 말: > > Hi, > > I have this code https://play.golang.org/p/9o5TReZ7jT3 > <https://play.golang.org/p/9o5TReZ7jT> > > My idea was to generate all possible combinations pretty much this: > > aaa > bbb > ccc > abb > acc > baa > bbb > bcc > caa > cbb > ccc > aba > abb > abc > > you get the picture I think. > > I got this solution but the objective is to simplify the solution without > using channels if possible : > > package main > > import "fmt" > > func GenerateCombinations(alphabet string, length int) <-chan string { > c := make(chan string) > > go func(c chan string) { > defer close(c) > > AddLetter(c, "", alphabet, length) > }(c) > > return c > } > > func AddLetter(c chan string, combo string, alphabet string, length int) { > if length <= 0 { > return > } > > var newCombo string > for _, ch := range alphabet { > newCombo = combo + string(ch) > c <- newCombo > AddLetter(c, newCombo, alphabet, length-1) > } > } > > func main() { > > list := "abc" > > for combination := range GenerateCombinations(list, 3) { > if len(combination) == 3 { > fmt.Println(combination) > } > > } > > fmt.Println("Done!") > } > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.