// 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 MainClass { public delegate void Processor(int[] v); public static void Print(int[] v) { for(int i = 0; i < v.Length; i++) Console.Write(" " + v[i]); Console.WriteLine(); } public static void Combinations(int[] a, int ix, int[] v, int used, Processor p) { if(used < v.Length) { for(int i = ix + 1; i < a.Length; i++) { v[used] = a[i]; Combinations(a, i, v, used + 1, p); } } else { p(v); } } public static void Combinations(int[] a, int siz, Processor p) { Combinations(a, 0, new int[siz], 0, p); } public static void Main(string[] args) { int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; Combinations(a, 4, Print); } } }