// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; namespace E { public class Combiner { public delegate void Process(string[] comb); private static void Combine(string[] elms, Process p, string[] comb, int start, int ix) { if(ix < elms.Length/2) { for(int i = start; i < elms.Length; i++) { comb[ix] = elms[i]; Combine(elms, p, comb, i + 1, ix + 1); } } else { List tmp = new List(comb); tmp.AddRange(new List(elms).FindAll(delegate(string s) { return !tmp.Contains(s); } )); if(comb[0] == elms[0]) // <---- delete if necesarry p(tmp.ToArray()); } } public static void Combine(string[] elms, Process p) { Combine(elms, p, new string[elms.Length/2], 0, 0); } private static void Print(string[] comb) { for(int i = 0; i < comb.Length; i++) { if(i == comb.Length/2) { Console.Write(" - "); } else if(i > 0) { Console.Write(" "); } Console.Write(comb[i]); } Console.WriteLine(); } public static void Main(string[] args) { Combine(new string[] { "Alexander", "Benny", "Christian", "Dora", "Elin", "Frida" }, Print); } } }