// 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; class Perm { public static void WriteRecursive(string[] s, string prefix, int ix, bool[] used) { if(ix < s.Length) { for(int i = 0; i < s.Length; i++) { if(!used[i]) { used[i] = true; WriteRecursive(s, prefix + s[i], ix + 1, used); used[i] = false; } } } else { Console.WriteLine(prefix); } } public static void WritePerm(string[] s) { bool[] used = new bool[s.Length]; WriteRecursive(s, "", 0, used); } public static void Main(string[] args) { string[] s = { "aa", "bb", "cc", "dd" }; WritePerm(s); } }