// 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; namespace E { public class Program { public delegate void Process(string s); public static void Perm(int[] a, Process p, String prefix, int ix, bool[] used) { if(ix < a.Length) { for(int i = 0; i < a.Length; i++) { if(!used[i]) { used[i] = true; Perm(a, p, prefix + " " + a[i], ix + 1, used); used[i] = false; } } } else { p(prefix); } } public static void Perm(int[] a, Process p) { bool[] used = new bool[a.Length]; Perm(a, p, "", 0, used); } public static void Main(string[] args) { Perm(new int[] { 1, 2, 5, 7 }, delegate(string s) { Console.WriteLine(s); }); } } }