Path: news.mathworks.com!not-for-mail
From: "us " <us@neurol.unizh.ch>
Newsgroups: comp.soft-sys.matlab
Subject: Re: eliminate identical raws
Date: Sat, 16 Feb 2008 18:16:01 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 42
Message-ID: <fp7991$656$1@fred.mathworks.com>
References: <27823314.1203129850043.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "us " <us@neurol.unizh.ch>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203185761 6310 172.30.248.35 (16 Feb 2008 18:16:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 16 Feb 2008 18:16:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:451843


vladimir:
<SNIP combinatorial evergreen...

one of the other many solutions is outlined below 
(including the comparison with a more traditional one as 
shown by others)...
timing on a wintel c2.2*2.4/2gb/winxp.sp2/r2008a

us

% the data
     a=[3,3,3,6,6,3,3,7];
% the engine
tic;
     as=sum(a);
     au=unique(a);
     na=numel(a);
     nu=numel(au);
     x=cell(na,1);
     ap=repmat({au},1,na);
     [x{1:na,1}]=ndgrid(ap{:});
     x=reshape(cat(na+1,x{:}),[],na);
     xs=whos('x');
     x=x(sum(x,2)==as,:);
     x=x(:,end:-1:1);
toc
% comparison with a more traditional solution
tic;
     p=perms(a);
     ps=whos('p');
     pu=unique(p,'rows');
toc
% - max temp sizes and <equal>
     disp([xs.bytes;ps.bytes;isequal(x,pu)]);

%{
Elapsed time is 0.051470 seconds. % sol #1
Elapsed time is 0.182210 seconds. % sol #2
      419904 % <- x max size
     2580480 % <- p max size
           1 % <- res are equal
%}