// 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 struct Row { public byte[] Data; } public struct RowPair { public int Ix1; public int Ix2; } public class Program { private static Random rng = new Random(); public static Row GenRow() { Row res; res.Data = new byte[8]; for(int i = 0; i < 8; i++) { res.Data[i] = (byte)rng.Next(0, 255); } return res; } public static Row[] GenMultiRows(int n) { Row[] res = new Row[n]; for(int i = 0; i < n; i++) res[i] = GenRow(); return res; } public static int Diff(Row r1, Row r2) { int res = 0; for(int i = 0; i < 8; i++) { res += (r1.Data[i] - r2.Data[i]) * (r1.Data[i] - r2.Data[i]); } return res; } public static RowPair FindMostLike(Row[] v) { int maxdif = int.MaxValue; RowPair maxix; maxix.Ix1 = -1; maxix.Ix2 = -1; for(int i = 0; i < v.Length - 1; i++) { for(int j = i + 1; j < v.Length; j++) { int tmp = Diff(v[i],v[j]); if(tmp < maxdif) { maxix.Ix1 = i; maxix.Ix2 = j; maxdif = tmp; } } } return maxix; } public static void Main(string[] args) { Row[] v = GenMultiRows(50); RowPair mx = FindMostLike(v); Console.WriteLine(mx.Ix1 + " " + mx.Ix2); } } }