Re: All componens different
- To: mathgroup at smc.vnet.net
- Subject: [mg112004] Re: All componens different
- From: thomas <thomas.muench at gmail.com>
- Date: Tue, 24 Aug 2010 06:13:39 -0400 (EDT)
- References: <i4t5qb$g2q$1@smc.vnet.net>
On Aug 23, 8:51 am, "Dr. Wolfgang Hintze" <w... at snafu.de> 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
How about:
d2[v_: List] := (Length[v] == Length[DeleteDuplicates[v]])
or (prior to version 7):
d2[v_: List] := (Length[v] == Length[Union[v]])
thomas