// 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; using System.Collections.Generic; namespace E { public class Program { public static int FindLowestMissingVal(List lst, int startval) { List slst = new List(lst); slst.Sort(); int ix = 0; while(slst[ix] != startval) ix++; while(slst[ix+1] == slst[ix] + 1) ix++; return slst[ix]+1; } public static void Main(string[] args) { List lst = new List(new int[] { 0, 2, 1, 22, 6, 924, 7 }); Console.WriteLine(FindLowestMissingVal(lst, 6)); Console.WriteLine(FindLowestMissingVal(lst, 0)); } } }