On Wed, 23 May 2018 00:25:49 -0700 Karan Chaudhary <fghj...@gmail.com> wrote:
> 
> One other simpler (and not so elegant) solution is to use separate set for 
> each element.
> 
> https://play.golang.org/p/9ZSRfAyOX4-
> 
> @Bakul's solution sounds good but haven't tried to understand it clearly.

See https://play.golang.org/p/_DrcHFTpHox

I first implemented it in k and then translated it fairly
mechanically to Go. [BTW, this is where Go not having generics
makes things a bit messy!]

The solution may seem cryptic but it is using typical array
programming components: each, reduce, cross-product, filter,
concatenate etc.  Once you develop a correct solution, you can
convert it to avoid building intermediate vectors + add other
optimizations. [Ideally done by a source to source converter]

> On Wednesday, 23 May 2018 11:46:15 UTC+5:30, Sankar wrote:
> >
> > Use an array instead of a slice. An array has a fixed size and can be used 
> >> as a key to a map
> >>
> >> https://play.golang.org/p/xxxmrwpx08A
> >>
> >
> > This seem to not work. The arr is returning only duplicate elements in 
> > your playground url. 
> >
> > For example:
> >
> >        var arr [][]int
> > for mem := range m {
> > fmt.Println("Appending: ", mem[:])
> > arr = append(arr, mem[:])
> > }
> > fmt.Println("Final arr is:", arr)
> >
> > the output is:
> >
> > Appending:  [-1 0 1]
> > Appending:  [-1 -1 2]
> > Final arr is: [[-1 -1 2] [-1 -1 2]]
> >
> > I am not really able to understand why the above code works so. The 
> > "Appending" and the "Final arr" statements have different values.

-- 
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.

Reply via email to