Re: All componens different
- To: mathgroup at smc.vnet.net
- Subject: [mg112014] Re: All componens different
- From: Herman Kuun <oomkoos1 at gmail.com>
- Date: Tue, 24 Aug 2010 06:15:30 -0400 (EDT)
Another solution d1[v_] := ( list = v // Flatten; Length[list] == Length[Union[list, list]] ) Simple example: listV1 = {1, {2, 3}, 4, 5}; listV2 = {1, {2}, {2, 3}, 4}; d1[listV1] True d1[listV2] False Regards On Mon, Aug 23, 2010 at 8:51 AM, Dr. Wolfgang Hintze <weh 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 > > >