Re: All componens different

• To: mathgroup at smc.vnet.net
• Subject: [mg112015] Re: All componens different
• From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
• Date: Tue, 24 Aug 2010 06:15:41 -0400 (EDT)

```Hi,

faster and shorter is

d2[v_] := Length[Union[v]] === Length[v]

Try something like

data = RandomSample[Range[10000], 10000];
d1[v_] := !
Or @@ Flatten[
Table[v[[i]] == v[[k]], {i, 1, Length[v]}, {k, i + 1, Length[v]}]];
d2[v_] := Length[Union[v]] === Length[v];
AbsoluteTiming[#[data]] & /@ {d1, d2}

gives here

{{51.339028, True}, {0.001555, True}}

Cheers
Patrick

On Mon, 2010-08-23 at 02:51 -0400, 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
>
>

```

• Prev by Date: Re: All componens different
• Next by Date: Re: Hanging indent in Print[] output?
• Previous by thread: Re: All componens different
• Next by thread: Re: All componens different