The top 3 lines of the function I posted yesterday were not correct but I couldn't edit them. Unfortunately, in my experiments with the slice I had changed them and didn't realize before posting. The correct version is:
package main import ( "fmt" "time") func get_partitions(set []string, out [][][]string) [][][]string { out = make([][][]string, 1) out[0] = make([][]string, 1) out[0][0] = make([]string, 0) if len(set) <= 1 { out[0][0] = set return out } for j := 0; j < len(set)*len(set)/2; j++ { i := j parts := make([][]string, 2) for _, item := range set { parts[i&1] = append(parts[i&1], item) i >>= 1 } pts := get_partitions(parts[1], out) for _, pt := range pts { i3 := len(out) - 1 if len(out[i3][len(out[i3])-1]) == 0 { out[i3][len(out[i3])-1] = parts[0] } else { out = append(out, [][]string{}) i3 += 1 out[i3] = append(out[i3], parts[0]) } if len(pt[0]) > 0 { for ptidx, _ := range pt { out[i3] = append(out[i3], pt[ptidx]) } } } } return out} func main() { set := []string{"1", "2", "3", "4", "5"} var out, ppp [][][]string out = make([][][]string, 1) // create & initialize 3D slice out[0] = make([][]string, 1) out[0][0] = make([]string, 1) t0 := time.Now() ppp = get_partitions(set, out) elapsed := time.Since(t0) fmt.Printf("Took %s\n", elapsed) fmt.Printf("\nGot the partition: %v\n", ppp) fmt.Println(len(ppp))} -- 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.