Skip to content

Instantly share code, notes, and snippets.

@yoavlt
Created February 20, 2014 04:47
Show Gist options
  • Save yoavlt/9107238 to your computer and use it in GitHub Desktop.
Save yoavlt/9107238 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func _genP(slice []bool, i, n int, ch chan []bool) {
if n == i {
ch <- slice
return
}
slice1 := make([]bool, n)
copy(slice1, slice)
slice2 := make([]bool, n)
copy(slice2, slice)
slice1[i] = true
slice2[i] = false
_genP(slice1, i+1, n, ch)
_genP(slice2, i+1, n, ch)
}
func genP(n int, ch chan []bool) {
slice := make([]bool, n)
_genP(slice, 0, n, ch)
close(ch)
}
func main() {
ch := make(chan []bool)
go genP(5, ch)
for v := range ch {
fmt.Println(v)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment