And a little better way to create `numMem`

https://play.golang.org/p/fAWgSpi2CKR


On Wednesday, 23 May 2018 12:55:49 UTC+5:30, Karan Chaudhary 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.
>
>  
>
> 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.
>>  
>> -- 
>> Sankar P
>> http://psankar.blogspot.com 
>>
>

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