Re: All componens different
- To: mathgroup at smc.vnet.net
- Subject: [mg112002] Re: All componens different
- From: David Carraher <david_carraher at terc.edu>
- Date: Tue, 24 Aug 2010 06:13:18 -0400 (EDT)
Hi Wolfgang,
How about this ...?
d[v_] := Length[v] == Length[Union[v]]
If you want to verify that the list consists of natural numbers, you'll
have to put in that constraint in your definition of v.
Best regards,
David Carraher
*****
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