From: Pete Hodgson Date: 2008-11-07T02:39:28+09:00 Subject: Finding gaps in a sorted sequence Hi Folks, Given a sorted enumeration I need to find the first gap in a sequence. e.g. 3 == find_gap [1,2,4,5] nil == find_gap [1,2,3,4] Here's the best I can come up with def first_gap( seq ) seq.each_cons(2) do |l,r| _next = l.next return _next if r!= _next end nil end but it seems rather ugly. Anyone have a more elegant implementation? Cheers, Pete