From: Bryan Richardson Date: 2008-08-07T07:59:22+09:00 Subject: Re: Need help detecting overlapping ranges Actually, never mind what I said about this code in a previous post... I misunderstood it. I think it works perfectly... still testing!!! :) David A. Black wrote: > Hi -- > > I did something similar in trying to implement Martin's algorithm. I > haven't tested it beyond eyeballing the results for this one run: > > ranges = [(1..5), (7..11), (22..29), (5..8)].sort_by {|r| r.first } > outages = [ranges.shift] > > ranges.each do |r| > if outages[-1].include?(r.first) > outages[-1] = Range.new(outages[-1].first, r.last) > else > outages.push(r) > end > end > > p outages > > > David -- Posted via http://www.ruby-forum.com/.