// 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 static int[] Pair(int n) { int[] ix = new int[n]; ix[0] = 0; for(int i = 2; i <= ix.Length; i *= 2) { int d = ix.Length / i; for(int j = d; j < ix.Length; j += 2 * d) { ix[j] = i - 1 - ix[j - d]; } } return ix; } public static void Main(string[] args) { string[] a = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" }; int[] ix = Pair(a.Length); for(int i = 0; i < ix.Length; i += 2) { Console.WriteLine(a[ix[i]] + " - " + a[ix[i+1]]); } } } }