Re: All componens different

• To: mathgroup at smc.vnet.net
• Subject: [mg112008] Re: All componens different
• From: Alexei Boulbitch <alexei.boulbitch at iee.lu>
• Date: Tue, 24 Aug 2010 06:14:23 -0400 (EDT)

```Hello, Wolfgang,
one idea would be to use the property of the function Union[] to sort with deleting duplicates
and to draw the conclusion on the basis of the length comparison:

allDifferent1[v_List] := SameQ[Length[Union[v]], Length[v]];

or like this (which is all the same):

allDifferent2[v_List] := Length[#] & /@ SameQ[Union[v], v];

(* Below there are two lists to test it *)
(* u has all different terms, v has some terms equal to one another *)

u = Range[25];
v = Table[RandomInteger[{0, 5}], {25}]

allDifferent1[u]
allDifferent1[v]

True

False

Regards, Alexei

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

--
Alexei Boulbitch, Dr. habil.
Senior Scientist
Material Development

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 CONTERN
Luxembourg

Tel: +352 2454 2566
Fax: +352 2454 3566
Mobile: +49 (0) 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu

www.iee.lu

--

This e-mail may contain trade secrets or privileged, undisclosed or
otherwise confidential information. If you are not the intended
recipient and have received this e-mail in error, you are hereby
notified that any review, copying or distribution of it is strictly
prohibited. Please inform us immediately and destroy the original

__________ Information from ESET NOD32 Antivirus, version of virus signature database 5391 (20100823) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

```

• Prev by Date: Re: Hanging indent in Print[] output?
• Next by Date: finding a symplectic recursion fixed point
• Previous by thread: Re: All componens different
• Next by thread: Re: All componens different