Re: All componens different
- To: mathgroup at smc.vnet.net
- Subject: [mg112010] Re: All componens different
- From: Christoph Lhotka <christoph.lhotka at univie.ac.at>
- Date: Tue, 24 Aug 2010 06:14:47 -0400 (EDT)
Hallo,
I suggest
d2[v_] := Length[Union[v]] == Length[v]
or
d3[v_] := LeafCount[v] - 1 == Length[v]
where d2 seems to be faster on my computer.
Best regards,
Christoph
On 23/08/2010 08: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
>
>
>
>