// 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 Permuting { public delegate void Processor(string s); public static void Print(string s) { Console.WriteLine(s); } private static void Permute(string prefix, int ix, List> data, Processor p) { foreach(string s in data[ix]) { if(ix >= data.Count - 1) { p(prefix + s); } else { Permute(prefix + s, ix + 1, data, p); } } } public static void Permute(List> data, Processor p) { Permute("", 0, data, p); } public static void Main(string[] args) { List> data = new List>(); data.Add(new List()); data.Add(new List()); data.Add(new List()); data[0].Add("A"); data[0].Add("B"); data[0].Add("C"); data[0].Add("D"); data[1].Add("X"); data[1].Add("Y"); data[1].Add("Z"); data[2].Add("1"); data[2].Add("2"); Permute(data, Print); } } }