// 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) { if(ix < a.Length) { for(int i = 0; i < a.Length; i++) { Perm(a, p, prefix + " " + a[i], ix + 1); } } else { p(prefix); } } public static void Perm(int[] a, Process p) { Perm(a, p, "", 0); } public static void Main(string[] args) { Perm(new int[] { 1 }, delegate(string s) { Console.WriteLine(s); }); Perm(new int[] { 1, 2 }, delegate(string s) { Console.WriteLine(s); }); Perm(new int[] { 1, 2, 3 }, delegate(string s) { Console.WriteLine(s); }); } } }