Re: All componens different
- To: mathgroup at smc.vnet.net
- Subject: [mg112000] Re: All componens different
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Tue, 24 Aug 2010 06:12:56 -0400 (EDT)
On Aug 23, 2010, at 2:51 AM, 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? I don't know about efficiency (but Sort should be order N*LogN (N==Length[v]) and Split order N, your expression is order N^2, the two solutions should be equivalent in memory used) but I'd solve the problem this way d2[v_]:==Length[Split[Sort[v]]]====Length[v] Alternatively d3[v_]:==Union[v]====Sort[v] but I don't know the time or space complexity of Union. Regards, Ssezi