That's definitely more memory efficient, but not much more computationally
efficient. There's probably a much cleverer way to compute the unique
permutations of a set of values that contain repetitions. It's arguable
that this is what permutations ought to do in the first place.

On Thu, Nov 19, 2015 at 4:06 PM, David P. Sanders <dpsand...@gmail.com>
wrote:

>
>
> El jueves, 19 de noviembre de 2015, 14:45:41 (UTC-6), Ratan Sur escribió:
>>
>> I want to get all the unique permutations of an array of a certain length
>> and this is the only way I currently know how to do it in one line. Is
>> there a builtin function for this?
>>
>> julia> unique(collect(permutations([1;0;0;0;1])))
>> 10-element Array{Array{Int64,1},1}:
>>  [1,0,0,0,1]
>>  [1,0,0,1,0]
>>  [1,0,1,0,0]
>>  [1,1,0,0,0]
>>  [0,1,0,0,1]
>>  [0,1,0,1,0]
>>  [0,1,1,0,0]
>>  [0,0,1,0,1]
>>  [0,0,1,1,0]
>>  [0,0,0,1,1]
>>
>>
> It turns out that the following works:
>
> unique(permutations([1, 0, 0, 0, 1]))
>
>
>

Reply via email to