Re: All componens different
- To: mathgroup at smc.vnet.net
- Subject: [mg112005] Re: All componens different
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Tue, 24 Aug 2010 06:13:50 -0400 (EDT)
- References: <i4t5qb$g2q$1@smc.vnet.net>
On 23/08/10 07:51, Dr. Wolfgang Hintze wrote:
> Given a list v of natural numbers I'm looking for a function d[v_] that
> returns True if all components are different and False otherwise.
>
> One solution is
>
> d1[v_] := ! Or @@ Flatten[Table[v[[i]] == v[[k]], {i, 1, Length[v]},
> {k, i + 1, Length[v]}]]
>
> Can you find more efficient (and elegant) solutions?
>
> Regards,
> Wolfgang
>
>
In[1]:= dl[l_] := (Length[Union[l]] == Length[l]);
In[2]:= dl[{1, 2, 5, 6, 8, 3}]
Out[2]= True
In[3]:= dl[{1, 2, 3, 6, 8, 3}]
Out[3]= False
David Bailey
http://www.dbaileyconsultancy.co.uk