On Thu, 11 Oct 2018, Riccardo (Jack) Lucchetti wrote: > If I'm not mistaken, this is more or less what we came up with in the end
[...] Actually, this is slightly faster: <hansl> function strings powerset(strings S) scalar l = nelem(S) scalar N = 2^l matrix P = zeros(N,l) matrix s = seq(0, N-1)' loop i=1..l --quiet matrix a = s % 2 matrix P[,i] = a matrix s = (s-a)/2 endloop strings PS = array(N) loop i = 1..N --quiet string c = "" loop j = 1..l --quiet if P[i, j] c = c ~ " " ~ S[j] endif endloop PS[i] = c endloop return PS end function </hansl> ------------------------------------------------------- Riccardo (Jack) Lucchetti Dipartimento di Scienze Economiche e Sociali (DiSES) Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucchetti(a)univpm.it http://www2.econ.univpm.it/servizi/hpp/lucchetti -------------------------------------------------------