Am 11.10.2018 um 23:28 schrieb Riccardo (Jack) Lucchetti:
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>
Hi Jack, without having checked whether this is intended but the first
entry in the PwrSet string array is empty.
Artur