Build all combinations of strings

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Jun 11 11:22:20 PDT 2012


On 6/11/12, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> Also I think the formal word of what I'm looking for is a "powerset".
>

Hmm wrong, not looking a powerset. Here's one anyway which bearophile
posted in another thread:
import std.stdio: writeln;
auto powerSet(T)(T[] items) {
   auto r = new T[][](1, 0);
   foreach (e; items) {
       T[][] rs;
       foreach (x; r)
           rs ~= x ~ [e];
       r ~= rs;
   }
   return r;
}
void main() {
   writeln(powerSet([1, 2, 3]));
}

So that's not what I'm looking for.


More information about the Digitalmars-d-learn mailing list